标签:play ret pid color 哈哈 define sed bsp ack
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1205
题目描述: N种糖果, 每种有M个, 问你能不能每天吃和前一天不同的糖果将这些糖果都吃完
解题思路: 很简单的鸽巢原理, 找出最多的糖果数, 如果剩下的能够将这最多的糖果数之间的空隙也就是maxnum-1填充满就可以了
代码:
#include <iostream> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iterator> #include <cmath> #include <algorithm> #include <stack> #include <deque> #include <map> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define mem0(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,0x3f,sizeof(a)) #define fi(n) for(i=0;i<n;i++) #define fj(m) for(j=0;j<m;j++) #define sca(x) scanf("%d",&x) #define scalld(x) scanf("%I64d",&x) #define print(x) printf("%d\n", x) #define printlld(x) printf("%I64d\n",x) #define de printf("=======\n") typedef long long ll; using namespace std; const int maxn = 1e6 + 10; int a[maxn]; int main() { int t; sca(t); while( t-- ) { int n; sca(n); int maxnum = -1; int index = -1; for( int i = 1; i <= n; i++ ) { sca(a[i]); if( a[i] > maxnum ) { maxnum = a[i]; index = i; } } int sum = 0; int flag = 0; for( int i = 1; i <= n; i++ ) { if( index != i ) { sum += a[i]; } if( sum >= maxnum-1 ) { flag = 1; break; } } if( flag ) printf("Yes\n"); else printf("No\n"); } return 0; }
思考: 挺有意思的啊, 哈哈哈哈哈哈, 组合数学, 之前把那本黑书前三章看了几遍, 是时候回顾并继续往下看了,还有别忘了看高数
http://acm.hdu.edu.cn/showproblem.php?pid=1205
标签:play ret pid color 哈哈 define sed bsp ack
原文地址:http://www.cnblogs.com/FriskyPuppy/p/7403627.html