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 |
我不知道你是用什么方法做,其实这题只需要判断公约数就可以了In Reply To:谁帮我看看这个,用递归做的,"Wrong Answer" Posted by:hanhui8301 at 2006-05-29 17:03:59 > #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator