题目:传送门

如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
    int T,n,a;
    scanf("%d",&T);
    while(T--) {
        scanf("%d",&n);
        int sum2=0,sum1=0;
        for(int i=0;i<n;i++) {
            scanf("%d",&a);
            sum2 += a/2;
            if(a%2==1) sum1++;
        }
        if(sum1==0) printf("%d\n",sum2*2);
        else printf("%d\n",sum2/sum1*2+1);
    }
}

 

相关文章:

  • 2021-07-06
  • 2021-06-09
  • 2021-07-30
  • 2021-12-07
  • 2021-09-12
  • 2021-07-30
  • 2022-01-21
  • 2021-11-22
猜你喜欢
  • 2022-01-06
  • 2022-02-19
  • 2021-12-10
  • 2021-05-17
  • 2021-10-23
  • 2021-09-29
  • 2021-06-25
相关资源
相似解决方案