http://poj.org/problem?id=3370
2012-10-19 09:07
489 查看
题意:万圣节时有n个人向m个邻居要糖果,每个邻居所要分化的糖果一定,为了能使要来的糖果能使n个人均分,问是否存在一个连续邻居满足要求,如果满足则输出,否者输出no sweets。
思路:由于n小于等于m,根据雀巢原理,则一定存在一个连续的邻居。
AC代码:
思路:由于n小于等于m,根据雀巢原理,则一定存在一个连续的邻居。
AC代码:
#include<iostream> #include<string.h> #include<cstdio> #define N 100005 #define CLR(arr,val) memset(arr,val,sizeof(arr)) using namespace std; int s ,flag ; long long sum ; void in(int &a) { char ch; while((ch=getchar())>'9'||ch<'0'); for(a=0;ch>='0'&&ch<='9';ch=getchar()) a=a*10+ch-'0'; } int main() { int m,n; while(1){ in(m),in(n); if(m+n==0) break; CLR(s,0); CLR(sum,0); CLR(flag,0); for(int i=1;i<=n;++i){ in(s[i]); sum[i]=sum[i-1]+s[i]; } for(int i=1;i<=n;++i){ int x=sum[i]%m; if(x==0){ for(int j=1;j<=i;++j) printf("%d ",j); printf("\n"); break; } if(flag[x]){ int y=flag[x]; for(int j=y+1;j<=i;++j) printf("%d ",j); printf("\n"); break; } flag[x]=i; } }return 0; }
相关文章推荐
- http://poj.org/problem?id=3468
- http://poj.org/problem?id=3083
- http://poj.org/problem?id=2481 树状数组+优先队列
- 2-sat&&http://poj.org/problem?id=3648
- POJ 2828 Buy Ticketshttp://poj.org/problem?id=2828
- http://poj.org/problem?id=3264&&RMQ
- Biorhythms&&http://poj.org/problem?id=1006
- POJ 1251(http://poj.org/problem?id=1251)
- http://poj.org/problem?id=1276
- http://poj.org/problem?id=1598
- Graph Coloring&&http://poj.org/problem?id=1419最大团问题
- poj3295 http://poj.org/problem?id=3295
- poj 1061 青蛙的约会 二元一次不定方程 http://poj.org/problem?id=1061
- http://poj.org/problem?id=1125 最短路径
- http://poj.org/problem?id=1125
- http://poj.org/problem;jsessionid=57CE7F39567FF9BFA128CDB4A2E8D728?id=2553
- http://poj.org/problem?id=1195二维树状数组
- http://poj.org/problem?id=1001
- http://poj.org/problem?id=2413
- http://poj.org/problem?id=3781&&Nth Largest Value