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:大家不要被样例欺骗 其实这个是鸽巢原理 去看组合数学书吧 Posted by:20072631 at 2009-10-10 08:26:58 > #include <iostream> > using namespace std; > #define MAXN 100000 > int a[MAXN], ind[MAXN]; > int main() > { > int c, n; > while(scanf("%d %d",&c,&n) == 2 && (n || c)) > { > for (int i=0; i<c; ++i) > ind[i] = -1; > for (int i=0; i<n; ++i) > { > scanf("%d",&a[i]); > } > int sum = 0; > ind[0] = 0; > bool found = false; > for (int i=0; i<n; ++i) > { > sum = (sum + a[i]) % c; > if (ind[sum] >= 0) > { > int checksum = 0; > for (int j=ind[sum]; j<=i; ++j) > { > checksum = (checksum+a[j])%c; > printf("%d",j+1); > if (j < i) printf(" "); > else puts(""); > } > found = true; > break; > } > ind[sum] = i+1; > } > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator