Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 为什么啊，一直wa ，心都碎了！那位指点一下！源代码如下：

Posted by 20091000302 at 2010-07-30 15:06:54 on Problem 2142
```#include<iostream>
using namespace std;

int a,b,c;
int x,y,x0,y0;
int min_num,min_w;

int extern_gcd(int a,int b)
{
int t,d;
if(b==0){x0=1,y0=0;return a;}
d=extern_gcd(b,a%b);
t=x0;
x0=y0;
y0=t-(a/b)*y0;
return d;
}

int getx(int t)
{
return abs(c*x0+b*t);
}
int gety(int t)
{
return abs(c*y0-a*t);
}

int cal_xy(int z1,int z2)
{
return z1+z2;
}
int cal_w(int z1,int z2)
{
return z1*a+z2*b;
}

void cmp(int t)
{
int x1,y1,t1,t2;
x1=getx(t);
y1=gety(t);
t1=cal_xy(x1,y1);
if(t1<min_num)
{
x=x1;
y=y1;
min_num=t1;
}
else if(t1==min_num)
{
t2=cal_w(x1,y1);
if(t2<t1){x=x1;y=y1;min_w=t2;}
}
}

int main()
{
int i,d,flag=0;
while(EOF!=scanf("%d%d%d",&a,&b,&c))
{
flag=0;
if(!a&&!b&&!c)break;
if(a<b){d=a;a=b;b=d;flag=1;}
d=extern_gcd(a,b);
//		if(c%d){printf("no solution\n");continue;}
c=c/d;
a=a/d;
b=b/d;

x=getx(0);
y=gety(0);
min_num=cal_xy(x,y); // 计算 |x|+|y|；
min_w=cal_w(x,y); // 计算 a*|x|+b*|y|
cmp(c*y0/a);
cmp(c*y0/a-1);
cmp(c*y0/a+1);
if(!flag)printf("%d %d\n",x,y);
else printf("%d %d\n",y,x);
}
return 0;
}```

Followed by: