标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 76 Accepted Submission(s): 68
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤105) -- the number of kinds of characters. The second line contains n integers a1,a2,...,an (0≤ai≤104).
Output
For each test case, output an integer denoting the answer.
1 #include <cstdio> 2 3 int main() 4 { 5 int T, n; 6 scanf("%d", &T); 7 while(T--){ 8 scanf("%d", &n); 9 int odd = 0; //记录奇数字符有多少个 10 int sum = 0; //记录总和 11 int num; 12 while(n--){ 13 scanf("%d", &num); 14 if(num&1){ 15 ++odd; 16 sum += num-1; 17 } 18 else{ 19 sum += num; 20 } 21 } 22 if(odd == 0){ //只有偶数字符 23 printf("%d\n", sum); 24 } 25 else{ 26 sum >>= 1; //得到能够分配的对数 27 printf("%d\n", sum/odd*2+1); 28 } 29 } 30 return 0; 31 }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5692896.html