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

程序修改,请教

Posted by Leon0916 at 2008-05-30 20:38:40 on Problem 1006
我自己先写了一个枚举的实现,但是耗时太大了,后来看到有人留言说用中国余数法,自己也试着写了一个,用时40多MS,看到别人写的用时很少,所以把代码帖出来想让大家帮忙看看,谢谢了。

#include <stdio.h>

int main(int argc, char* argv[])
{
	int p,e,i,d, index;
	int day;
	int x = 28*33*6;
	int y = 23*33*19;
	int z = 23*28*2;
	index = 0;
	

	do
	{
		scanf("%d %d %d %d", &p,&e, &i, &d);
		if(p == -1 && e == -1 && i == -1 && d == -1)
			break;
		p = p%23;
		e = e%28;
		i = i%33;
		day = (p*x + e*y + i*z) % 21252;
		if(day == d)
			day += 21252;
		printf("Case %d: the next triple peak occurs in %d days.\n", ++index,day-d >= 0 ? day-d : day-d+21252);
	}while(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