zoukankan      html  css  js  c++  java
  • 鸽巢原理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 ");
                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(" ");
                    break;
                }
                else if(brr[i]==0)
                {
                    printf("1");
                    for(int j=2;j<=i;j++)
                    printf(" %d",j);
                    printf(" ");
                    break;
                }
                else
                {
                    crr[brr[i]]=i;
                }
            }
        }
        return 0;
    }

  • 相关阅读:
    while练习题
    流程控制之for循环
    流程控制之while循环
    流程控制之if判断
    作业
    基本运算符
    输入输出
    基本数据类型
    变量part2
    JDBC中创建表
  • 原文地址:https://www.cnblogs.com/lyf123456/p/3368970.html
Copyright © 2011-2022 走看看