Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:大家不要被样例欺骗 其实这个是鸽巢原理 去看组合数学书吧

Posted by qidi at 2010-11-23 12:42:38 on Problem 3370
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator