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 Nedvid at 2007-10-12 11:25:46 on Problem 3039
#include<stdio.h>
#include<math.h>
#define INF 0.0000000001
void main()
{
	long i,j,aa,bb;double temp,rest,m,n,x;
	bool flag;
	while(scanf("%lf%lf",&m,&n)!=EOF)
	{
		flag=true;

		if(m>n){
			x=m;
			m=n;
			n=x;
			flag=false;
		}
		if(m==0&&n!=0){printf("1 32767\n");continue;}
		if(n==0&&m!=0){printf("32767 1\n");continue;}
		i=1;j=1;rest=(double)m/n;temp=INF;
	while(i<=32767&&j<=32767)
	{ 
		x=fabs((double)i*1.0/(double)j*1.0);
        if((x-rest) < temp && (m*j!=n*i)){
		temp=fabs(x-rest);
		aa=i;bb=j;
	}
	if( x>=rest )
		j++;
	else
		i++;
	}	
	if(flag) 
	printf("%ld %ld\n",aa,bb);
	else 
	printf("%ld %ld\n",bb,aa);
	}
}
提交n次总是wrong,实在是没办法了,测试都对,求大牛指点,可发我邮箱,再次小弟拜谢!!

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