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 stupidjohn at 2010-05-30 19:15:26 on Problem 1006
#include<iostream>
using namespace std;
int x,y,flag,times;
int ret[3];
int chu[3]={23,28,33};
int function(int a,int b,int &x,int &y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	else
	{
		int tmp;
		function(b,a%b,x,y);
		tmp=x;
		x=y;
		y=tmp-(a/b)*y;
		return x*a;
	}
}
void run()
{
	int i,sum=0,d;
	for(i=0;i<3;i++)
	cin>>ret[i];
	if(ret[0]==-1)
	{
		flag=0;
		return;
	}
	cin>>d;
	for(i=0;i<3;i++)
	sum+=function(23*28*33/chu[i],chu[i],x,y)*ret[i];
	while(sum<=d) sum+=23*28*33;
	while(sum>d+23*28*33) sum-=23*28*33;
	cout<<"Case "<<times<<": the next triple peak occurs in ";
	cout<<sum-d;
	cout<<" days."<<endl;
	times++;
}
int main()
{
	times=1;
	flag=1;
	while(flag)
		run();
	return 1;
}



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