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 zhujie at 2006-03-12 22:52:22 on Problem 1079
In Reply To:一个奇怪的现象! Posted by:zhujie at 2006-03-12 22:30:42
#include <stdio.h>
#include <math.h>

#define EPI 1e-14
bool More(double x,double y)
{
	return (x - y > EPI);
}
bool Equal(double x,double y)
{
	return (fabs(x - y) < EPI);
}
int main()
{
	int gain,loss,Deno,Mole;
	double Brate,Arate,Crate;
	bool ok;
	while (scanf("%d%d",&gain,&loss) != EOF)
	{
		
		Arate = Brate = double(gain) / loss;
		Deno = 1;
		while (Deno <= loss)
		{
			 ok = false;
			 Mole =int(ceil(Deno * (Arate - Brate)));
			 if (Mole == 0)  Mole ++;
			 while (1)
			 {
				 Crate = double(Mole) / Deno;
			
				 if (Equal(Crate,Arate-Brate)) {Mole ++ ;continue;}
				 if (More(Crate,Arate+Brate) || Equal(Crate,Arate+Brate))  break;
				 Brate = fabs(Crate - Arate);
				 ok = true;
				 Mole ++;
			 }
			 if (ok)  printf("%d/%d\n",Mole-1,Deno); 
			 Deno++;
		}
		printf("\n");
	}
	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