标签:style blog http color os io 2014 for
鸽笼原理题,以后得好好研究下相关题目。
1 /* 2 ID:esxgx1 3 LANG:C++ 4 PROG:poj2356 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <iostream> 9 #include <algorithm> 10 using namespace std; 11 12 #define NN 10007 13 14 int _sum[NN], *sum = &_sum[1]; 15 int lookup[NN]; 16 17 int main(void) 18 { 19 #ifndef ONLINE_JUDGE 20 freopen("in.txt", "r", stdin); 21 #endif 22 23 int N, i; 24 scanf("%d", &N); 25 sum[-1] = 0; 26 for(i=0; i<N; ++i) { 27 int k; 28 scanf("%d", &k); 29 sum[i] = sum[i-1] + k; 30 if (lookup[sum[i] % N]) k = lookup[sum[i] % N]; 31 else if (!(sum[i] % N)) k = 0; 32 else k = -1; 33 34 if (k >= 0) { 35 printf("%d\n", i-k+1); 36 while(k <= i) { 37 printf("%d\n", sum[k] - sum[k-1]); 38 ++k; 39 } 40 break; 41 } else lookup[sum[i] % N] = i+1; 42 } 43 if (i >= N) printf("0\n"); 44 return 0; 45 }
2356 | Accepted | 744K | 94MS | G++ | 751B | 2014-07-29 08:35:46 |
POJ 2356 - Find a multiple,布布扣,bubuko.com
标签:style blog http color os io 2014 for
原文地址:http://www.cnblogs.com/e0e1e/p/poj_2356.html