zoukankan      html  css  js  c++  java
  • [HDOJ5744]Keep On Movin(水题)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5744

    题意:给你n个字符的数量,要求组合成多个回文串,问如何组合使得这个回文串集合里最短的那一条回文串最长。

    分情况讨论,所给的n个字符数量都是偶数或仅有一个奇数,那么这个串可以是全部字符组合成的,长度为∑ai。

    如果有两个以上的奇数量(k)字符,那么最好的方法就是平均分成k个回文串。把这些奇数量的字符数量-1,则剩下的都是偶数的了。之后平均分配给所有串,每个串的长度为(sum/2)/odd*2+1

     1 /*
     2 ━━━━━┒ギリギリ♂ eye!
     3 ┓┏┓┏┓┃キリキリ♂ mind!
     4 ┛┗┛┗┛┃\○/
     5 ┓┏┓┏┓┃ /
     6 ┛┗┛┗┛┃ノ)
     7 ┓┏┓┏┓┃
     8 ┛┗┛┗┛┃
     9 ┓┏┓┏┓┃
    10 ┛┗┛┗┛┃
    11 ┓┏┓┏┓┃
    12 ┛┗┛┗┛┃
    13 ┓┏┓┏┓┃
    14 ┃┃┃┃┃┃
    15 ┻┻┻┻┻┻
    16 */
    17 #include <algorithm>
    18 #include <iostream>
    19 #include <iomanip>
    20 #include <cstring>
    21 #include <climits>
    22 #include <complex>
    23 #include <fstream>
    24 #include <cassert>
    25 #include <cstdio>
    26 #include <bitset>
    27 #include <vector>
    28 #include <deque>
    29 #include <queue>
    30 #include <stack>
    31 #include <ctime>
    32 #include <set>
    33 #include <map>
    34 #include <cmath>
    35 using namespace std;
    36 #define fr first
    37 #define sc second
    38 #define cl clear
    39 #define BUG puts("here!!!")
    40 #define W(a) while(a--)
    41 #define pb(a) push_back(a)
    42 #define Rint(a) scanf("%d", &a)
    43 #define Rs(a) scanf("%s", a)
    44 #define Cin(a) cin >> a
    45 #define FRead() freopen("in", "r", stdin)
    46 #define FWrite() freopen("out", "w", stdout)
    47 #define Rep(i, len) for(int i = 0; i < (len); i++)
    48 #define For(i, a, len) for(int i = (a); i < (len); i++)
    49 #define Cls(a) memset((a), 0, sizeof(a))
    50 #define Clr(a, x) memset((a), (x), sizeof(a))
    51 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
    52 #define lrt rt << 1
    53 #define rrt rt << 1 | 1
    54 #define pi 3.14159265359
    55 #define RT return
    56 #define lowbit(x) x & (-x)
    57 #define onecnt(x) __builtin_popcount(x)
    58 typedef long long LL;
    59 typedef long double LD;
    60 typedef unsigned long long ULL;
    61 typedef pair<int, int> pii;
    62 typedef pair<string, int> psi;
    63 typedef pair<LL, LL> pll;
    64 typedef map<string, int> msi;
    65 typedef vector<int> vi;
    66 typedef vector<LL> vl;
    67 typedef vector<vl> vvl;
    68 typedef vector<bool> vb;
    69 
    70 const int maxn = 100100;
    71 int n;
    72 int a[maxn];
    73 int s1, s2, odd;
    74 
    75 int main() {
    76     // FRead();
    77     int T;
    78     Rint(T);
    79     W(T) {
    80         s1 = s2 = odd = 0;
    81         Rint(n);
    82         Rep(i, n) {
    83             Rint(a[i]);
    84             if(a[i] & 1) {
    85                 odd++;
    86                 s2 += a[i] - 1;
    87             }
    88             else s2 += a[i];
    89             s1 += a[i];
    90         }
    91         if(odd < 2) {
    92             printf("%d
    ", s1);
    93             continue;
    94         }
    95         printf("%d
    ", s2/2/odd*2+1);
    96     }
    97     RT 0;
    98 }
  • 相关阅读:
    stm32自带的flash分布图
    leetcode21
    使用redis缓存数据需要注意的问题以及个人的一些思考和理解
    Chapter 2 Open Book——2
    spring管理事务需要注意的
    如何避免在简单业务逻辑上面的细节上面出错
    leetcode387
    黑天鹅-简记
    java方法中只有值传递,没有引用传递
    Chapter 2 Open Book——1
  • 原文地址:https://www.cnblogs.com/kirai/p/5811514.html
Copyright © 2011-2022 走看看