hdu 1205 吃糖果 (鸽笼原理)
http://acm.hdu.edu.cn/showproblem.php?pid=1205 题意:有n种糖果,第i种糖果有a[i]个,相邻两次不能吃一样的糖果,问能否有办法吃完所有糖果... 思路:如果第i种糖果有k个的话,那么其他所有种类的糖果之和至少有k-1个,才可能吃完。复杂度O(n) 看到有人说是抽屉原理.....大概。。。?不过不太明显。。直接想就好吧
/* ***********************************************
Author :111qqz
Created Time :2016年02月29日 星期一 20时40分00秒
File Name :code/hdu/1205.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=1E6+7;
7int n;
8LL a[N];
9LL total;
1int main()
2{
3 #ifndef ONLINE_JUDGE
4 freopen("code/in.txt","r",stdin);
5 #endif
1 ios::sync_with_stdio(false);
2 int T;
3 cin>>T;
4 while (T--)
5 {
6 cin>>n;
7 total = 0;
8 for ( int i = 1 ; i <= n ; i++)
9 {
10 cin>>a[i];
11 total +=a[i];
12 }
1 bool ok = true;
2 for ( int i = 1 ; i <= n ; i++)
3 {
4 LL x;
5 x= total-a[i];
6 if (x<a[i]-1)
7 {
8 ok = false;
9 break;
10 }
11 }
1 if (ok)
2 {
3 puts("Yes");
4 }
5 else
6 {
7 puts("No");
8 }
}
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}