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

## Re:一直wrong， 求指点

Posted by 6100300115 at 2012-08-07 15:25:15 on Problem 2142
In Reply To:一直wrong， 求指点 Posted by:20101510 at 2012-08-03 11:05:58
```> #include<iostream>
> #include<cmath>
> using namespace std;
> void ExtendGcd(int a, int b, int &d, int &x, int &y)
> {
> 	if(b==0)
> 	   x = 1, y=0, d =a;
> 	else
> 	{
> 		ExtendGcd(b, a%b, d, x, y);
> 		int temp = x;
> 		x = y;
> 		y = temp - a/b*y;
> 	}
> }
> void swap(int &x, int &y)
> {
> 	int temp = x;
> 	x= y;
> 	y= temp;
> }
> int main()
> {
> 	int a, b, d;
> 	int D, x, y, x1, x2, y1, y2;
>
> 	while( cin>>a>>b>>d && (a+b+d))
> 	{
> 		if(a<b) swap(a, b);
> 		ExtendGcd(a, b, D, x, y);
>         x*=(d/D);
> 		y*=(d/D);
>
> 	    int t =  D*y/a;
>
>         x1 = x+b/D*t;
>         y1 = y-a/D*t;
>
> 	    if(D*y%a!=0)
> 		{
> 			y>0?t++:t--;
> 		    x2 = x+b/D*t;
> 			y2 = y-a/D*t;
> 		}
>
> 		if(abs(x1*1.0)+abs(y1*1.0)>abs(x2*1.0)+abs(y2*1.0))
> 		   x1 =x2, y1=y2;
> 		cout<<abs(x1*1.0)<<" "<<abs(y1*1.0)<<endl;
> 	}
> }
```

Followed by: