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

我是跳着数数的 居然47ms过了 之前不知道剩余定理

Posted by yanzhengfei at 2009-07-27 10:29:05 on Problem 1006
#include"iostream"
using namespace std;
int main()
{
	int p,e,i,d;
	int count=1;
	int n,k;
	while(1)
	{
		int flag=1;
		scanf("%d%d%d%d",&p,&e,&i,&d);
		if(p==-1&&e==-1&&i==-1&&d==-1)	break;
		for(n=1;n<=23;n++)
			if((n-p)%23==0)
				break;
		for(n;n<=667;n+=23)	
			if((n-e)%28==0)
				break;
		for(n;n<=21252;n+=644)
            if((n-i)%33==0)
					{
			           	flag=0;
				        if(n<=d) k=n-d+21252;
				        else k=n-d;
				        printf("Case %d: the next triple peak occurs in %d days.\n",count++,k);
				        break;
					}
        if(flag)
		{
			if(d==21252)k=21252;
			else d=21252-d;
			printf("Case %d: the next triple peak occurs in %d days.\n",count++,k);
		}
	}
	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