| ||||||||||
| 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 | |||||||||
Re:一直wrong, 求指点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:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator