鸽巢原理POJ-3370

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int arr[100050];
int brr[100050];
int crr[100050];
int c,n;
int main()
{
    while(scanf("%d %d",&c,&n)!=EOF&&c+n)
    {
        memset(crr,0,sizeof(crr));
        memset(arr,0,sizeof(arr));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&arr[i]);
        }
        brr[1]=arr[1];
        crr[brr[1]%c]=1;
        if(brr[1]%c==0)
        {
            printf("1\n");
            continue;
        }
        for(int i=2;i<=n;i++)
        {
            brr[i]=(brr[i-1]+arr[i])%c;
            if(crr[brr[i]])
            {
                printf("%d",crr[brr[i]]+1);
                for(int j=crr[brr[i]]+2;j<=i;j++)
                printf(" %d",j);
                printf("\n");
                break;
            }
            else if(brr[i]==0)
            {
                printf("1");
                for(int j=2;j<=i;j++)
                printf(" %d",j);
                printf("\n");
                break;
            }
            else
            {
                crr[brr[i]]=i;
            }
        }
    }
    return 0;
}

posted @ 2013-10-14 18:35  清风旋叶  阅读(147)  评论(0编辑  收藏  举报