poj 2356
终于又A了道题。。。容斥原理。
//============================================================================ // Name : 2356.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <cstdio> #include <cstring> using namespace std; int sum[10010], flag[10010], a[10010], from[10010]; int ans, n, tag, t; int main() { while(scanf("%d", &n)!=EOF){ memset(sum, 0, sizeof(sum)); memset(flag, 0, sizeof(flag)); memset(from, 0, sizeof(from)); for(int i = 1;i <= n;i++){ scanf("%d", &a[i]); } for(int i = 1;i <= n;i++){ sum[i] = sum[i-1] + a[i]; t = sum[i]%n; if(t == 0){ printf("%d\n", i); for(int j = 1;j <= i;j++){ printf("%d\n", a[j]); } break; } else{ if(flag[t] == 0){ flag[t] = 1; from[t] = i; } else{ printf("%d\n", i-from[sum[i]%n]); for(int j = from[sum[i]%n]+1;j <= i;j++){ printf("%d\n", a[j]); } break; } } } } return 0; }