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

最愚蠢的方法。。。。。要注意求出之后要减去21252

Posted by earnAlive at 2014-04-14 15:50:27 on Problem 1006
刚开始没有减去那个最大周期,导致一直WA,不过好像测试了很多数据都没有发现异常,贴上代码
#include<stdio.h>
#define PC 23 
#define EC 28 
#define IC 33
#define circle 21252

int triple(int p,int e,int i)
{
	while(p!=e||p!=i||e!=i)
	{
		if(p<=e&&p<=i)
		p+=PC;
		else if(e<=p&&e<=i)
		e+=EC;
		else if(i<=p&&i<=e)
		i+=IC;
	}
	if(p>circle)
	p-=circle;
	return p;
}

int main()
{
	int p,e,i,d;
	int num=0;
	int trip;
	while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF)
	{
		if(p==-1&&e==-1&&i==-1&&d==-1)
		break;
		if(p==d&&e==d&&i==d)
		printf("Case %d: the next triple peak occurs in %d days.\n",++num,circle);
		else
		{
			trip=triple(p,e,i);
			if(trip==d)
			printf("Case %d: the next triple peak occurs in %d days.\n",++num,circle);
			else if(trip<d)
			printf("Case %d: the next triple peak occurs in %d days.\n",++num,circle+trip-d);
			else 
			printf("Case %d: the next triple peak occurs in %d days.\n",++num,trip-d);
		}
	}	
	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