【ACM】hdu_1808_Halloween treats_201308132022
Halloween treats
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 434 Accepted Submission(s): 134
Special Judge
Your job is to help the children and present a solution.
The first line of each test case contains two integers c and n (1 ≤ c ≤ n ≤ 100000), the number of children and the number of neighbours, respectively. The next line contains n space separated integers a1 , ... , an (1 ≤ ai ≤ 100000 ), where ai represents the number of sweets the children get if they visit neighbour i.
The last test case is followed by two zeros.
#include <stdio.h>
#include <string.h>
int a[101000],b[101000];
int main()
{
int n,c;
while(scanf("%d %d",&c,&n),c||n)
{
int i,j,sum,begin,end;
memset(b,0,sizeof(b));
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
sum=0;
for(i=1;i<=n;i++)
{
sum=(sum+a[i])%c;
if(sum==0)
{
begin=1;
end=i;
break;
}
else if(!(b[sum]))
{
b[sum]=i;
}
else
{
begin=b[sum]+1;
end=i;
}
}
for(i=begin;i<=end;i++)
{
if(i<end)
printf("%d ",i);
else
printf("%d\n",i);
}
}
return 0;
}
//组合数学之抽屉原理 相关题目 poj 2356