| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪位大虾帮我看看哪里错了,先谢谢了我是看不出来了,虽然效率会比较差,但我觉得逻辑好像没问题阿
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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator