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

why I still WA(with the source)

Posted by windbells at 2004-07-20 23:16:32 on Problem 1079
#include<stdio.h>
#include<math.h>
int lcd(int a,int b)
{
	int c;
	while(b!=0)
	{
		c=b;
		b=a%b;
		a=c;
	}
	return a;
}
int main()
{
	int n[100],m[100],i,j,num,key,flag=0,k,size;
	double clj,a,c,d;
	for(i=0;;i++)
		if(scanf("%d%d",&n[i],&m[i])==EOF)
			break;
	size=i;
	for(k=0;k<size;k++)
	{
		clj=10;
		c=n[k]*1.0/m[k];
		for(i=1;i<=m[k];i++)
		{
			a=clj;
			num=(int)(i*n[k]/m[k]);
			key=num;
			for(j=0;j<=1;j++)
			{
				d=(num+j)*1.0/i;
				if(fabs(c-d)<a&&lcd(num+j,i)==1)
				{
					key=num+j;
					a=fabs(c-d);
				}
			}
			if(a<clj)
			{
				clj=a;
				printf("%d/%d\n",key,i);
			}
		}
		if(k!=size-1)
			printf("\n");
	}
}

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