NOJ [1285] The TT Candy

来源:互联网 发布:百度派 知乎 编辑:程序博客网 时间:2024/05/22 08:22
链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1285

此题的意思就是TT有n种糖果,每种糖果都有一定的数量。
但是TT吃糖果有个习惯,就是换着口味吃。当她吃了一颗糖果A后,她下一颗一定不吃糖果A,只能吃其他种类的。
现在问你TT能否吃完所有的糖果。
例如输入:
3
2 3 4
那么吃糖果的顺序可以是C B C B C B A C A,所以题意就是说这一连串的字符串,相邻两个字符不能是一样的。

题意讲完了,那么开始讲题解。
只要我们把糖果数量最多的那种糖果拎出来,记为X,然后把其他除X以外的糖果加起来的总和记为S,那么只要S + 1 >= X,
就一定能吃完了(想一想为什么),否则就无法吃完。

#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
int n, m;
__int64 s, p;
//freopen("data.in", "r", stdin);
//freopen("data.out", "w", stdout);

scanf("%d", &n);
while (n--)
{
s = p = 0;
scanf("%d", &m);
for (int i = 0; i < m; i++)
{
__int64 x;
scanf("%I64d", &x);
s += x;
if (x > p) p = x;
}
if (s - p + 1 >= p) printf("Yes\n");
else printf("No\n");
}

return 0;
}


0 0
原创粉丝点击