http://acm.timus.ru/problem.aspx?space=1&num=1032
http://poj.org/problem?id=2356
鸽巢原理
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<set> #include<map> #include<string> #include<queue> #include<stack> #include <iomanip> using namespace std; #define LL long long #define ULL unsigned long long const double eps=1e-6; const int INF=0x3f3f3f3f; const int N=10003; int a[N],f[N]; int main() { //freopen("data.in","r",stdin); int n; cin>>n; for(int i=1;i<=n;++i) cin>>a[i]; int tmp=0; int l,r; memset(f,-1,sizeof(f)); f[0]=0; for(int i=1;i<=n;++i) { if(a[i]%n==0) {cout<<"1"<<endl;cout<<a[i]<<endl;return 0;} tmp=(tmp+a[i])%n; if(f[tmp]==-1) f[tmp]=i; else {l=f[tmp];r=i;break;} } cout<<(r-l)<<endl; for(int i=l+1;i<=r;++i) cout<<a[i]<<endl; return 0; }