标签:
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 6535 | Accepted: 2849 | Special Judge |
Description
Input
Output
Sample Input
5 1 2 3 4 1
Sample Output
2 2 3
Source
#include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; #define N 10010 struct Node { int x,y,s; //下标,余数,前缀和 bool operator <(const Node &t)const { if(y!=t.y) return y<t.y; return x<t.x; } }p[N]; int main() { int n; int flag; int a[N]; while(scanf("%d",&n)!=EOF) { flag=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); p[i].s=p[i-1].s+a[i]; p[i].x=i; p[i].y=p[i].s%n; if(!flag && p[i].y==0) { flag=1; printf("%d\n",i); for(int j=1;j<=i;j++) printf("%d\n",a[j]); } } if(flag) continue; sort(p+1,p+n+1); for(int i=2;i<=n;i++) { if(p[i].y==p[i-1].y) { int &l=p[i-1].x; int &r=p[i].x; printf("%d\n",r-l); for(int j=l+1;j<=r;j++) printf("%d\n",a[j]); break; } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/hate13/p/4474805.html