码迷,mamicode.com
首页 > 其他好文 > 详细

鸽巢原理-poj3370

时间:2014-05-14 23:11:50      阅读:391      评论:0      收藏:0      [点我收藏+]

标签:blog   class   code   c   color   int   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
int main(int argc, char *argv[])
{
        int c = -1, n = -1;
        while (true) {
        scanf("%d%d",&c,&n);
            int arr[n],sum[n],b[n];
            if (c + n == 0) {
                return 0;
            }
            for (int i = 0; i < n; i++) {
                scanf("%d",&arr[i]);
                b[i] = -1;
            }
            sum[0] = arr[0] % c;
            b[sum[0]] = 0;
            int temp = -1, temp1 = 0;
            for (int i = 1; i < n; i++) {
                sum[i] = sum[i - 1] + arr[i];
                sum[i] %= c;
                if (sum[i] == 0) {
                    temp = -1;
                    temp1 = i;
                    break;
                }
                if (b[sum[i]] == -1) {
                    b[sum[i]] = i;
                } else {
                    temp = b[sum[i]];
                    temp1 = i;
                    break;
                }
            }
            for (int i = temp+1 ; i <= temp1; i++) {
                printf("%d%s",i+1," ");
            }
            printf("\n");
        }
    return 0;
}

 

鸽巢原理-poj3370,布布扣,bubuko.com

鸽巢原理-poj3370

标签:blog   class   code   c   color   int   

原文地址:http://www.cnblogs.com/ZhangJinkun/p/3728806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!