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

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:

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