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

谁帮我看看这个,用递归做的,"Wrong Answer"

Posted by hanhui8301 at 2006-05-29 17:03:59 on Problem 1061
#include<iostream.h>
int main(){
	long int x,y,m,n,l,z,d,count;
	long f(long,long,long);
	cin>>x>>y>>m>>n>>l;
	z=(y-x)%l;
	if(z){
		if(m==n){
			count=-1;
		}
		else{
			if(n>m){
				z=l-z;
				d=(n-m)%l;
			}
			else 
				d=(m-n)%l;
			count=f(z,d,l);
		}
	}
	else
		count=0;
	if(count<0)cout<<"Impossible"<<endl;
	else cout<<count<<endl;
	return 0;
}

long f(long z,long d,long l){
	long count,k;
	if(d){
		if(z%d==0){
			count=z/d;
			return count;
		}
		else {
			long d0=d;
			long z0=z;
			z=d0-z%d0;
			d=l%d0;			
			k=f(z,d,d0);
			if(k>0)
				count=(z0+k*l)/d0;
			else 
				return -1;
			return count;
		}
	}
	else 
		return -1;
}

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