HDU 5744

题意:

  给你不同的字符每个 ai 个,让你构造一些回文串,问你能达到这些回文串长度的最小值的最大值是多少

分析:

  要么直接组成单链.

  要么按落单的字符的数目将成对字符分摊取最短.

 1 #include <iostream>
 2 #include <cstdio> 
 3 using namespace std;
 4 int main()
 5 {
 6     int t, n;
 7     scanf("%d", &t);
 8     while(t--)
 9     {
10         long long one = 0, two = 0;
11         scanf("%d", &n);
12         for (int i = 1; i <= n; i++)
13         {
14             int x;
15             scanf("%d", &x);
16             if (x % 2) one++, x--; //单个的个数 
17             two += x / 2;    //成对的个数
18         }
19         if (one <= 1) printf("%d
", two * 2 + one); //可直接组成单链 
20         else printf("%lld
", two / one * 2 + 1); //单个的数目即链的数目 
21     }
22 }
我自倾杯,君且随意
原文地址:https://www.cnblogs.com/nicetomeetu/p/5762642.html