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 Cell at 2005-01-05 15:29:19 on Problem 2142
我是看不出来了,虽然效率会比较差,但我觉得逻辑好像没问题阿
sample也都没有问题
#include "stdio.h"
void f(const int &a,const int &b,const int &d,int &x,int &y)
{
	x=1;y=0;
	while (1)
	{
		if (a*x<b*y+d)
		{
			if (y==0&&(d-a*x)%b==0)
			{
				y=(d-a*x)/b;
				break;
			}
			++x;
			continue;
		}
		if (a*x==b*y+d)
			break;
		else
			++y;
	}
}
void main()
{
	int a,b,d,ax,bx,ay,by;
	while (scanf("%d %d %d",&a,&b,&d))
	{
		if (a==0&&b==0&&d==0)break;
		f(a,b,d,ax,bx);
		f(b,a,d,by,ay);
		if (ax+bx<ay+by||((ax+bx==ay+by)&&a*ax+b*bx<a*ay+b*by))
			printf("%d %d\n",ax,bx);
		else
			printf("%d %d\n",ay,by);
	}
}

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