Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:看看In Reply To:改了还是WA,谁帮我看看。。。code Pascal Posted by:My_loves at 2005-11-13 15:30:22 #include<iostream> using namespace std; #define N (100000+10) int a[N]; int b[N]; int sum[N]; int n; void solve() { int i; sum[0]=a[0]; sum[0]%=n; for(i=1;i<n;i++) { sum[i-1]%=n; sum[i]=sum[i-1]+a[i]; } sum[i-1]%=n; memset(b,0,sizeof(b)); int flag=0; int bb,e; for(i=0;i<n;i++) { if(sum[i]%n==0) { flag=1; bb=0; e=i; break; } } if(flag==0) { for(i=0;i<n;i++) { int t=sum[i]%n; if(b[t]==0) { b[t]=i; } else { // flag=1; bb=b[t]; e=i; break; } } } if(flag==1) { printf("%d\n",e+1); for(i=0;i<=e;i++) printf("%d\n",a[i]); } else { printf("%d\n",e-bb); for(i=bb+1;i<=e;i++) { printf("%d\n",a[i]); } } } void main() { int i; // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); // while( scanf("%d",&n);//!=EOF) { for(i=0;i<n;i++) { scanf("%d",&a[i]); } solve(); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator