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 |
请高手帮忙测试一下,指出哪组数据此程序运行结果是错误的!!!!/*#include<iostream.h> long num; int chu(long s,long n,long k) { s++; if(k==n) { if(s<num) num=s; return 0; } else if(k<n) { if(n-k<=2*k-n) { s+=n-k; if(s<num) num=s; } else { s=s+2*k-n-1; if(s<num) num=s; } return 0; } else { if(k%2==0) { chu(s,n,k/2); } else { chu(s,n,k-1); chu(s,n,k+1); } } return 0; } int main() { long k,n; while(cin>>n>>k) { if(n>=k) cout<<n-k<<endl; else { num=10000000; chu(-1,n,k); cout<<num<<endl; } } return 0; } */ #include<iostream.h> long num; int chu(long s,long n,long k) { s++; if(k==n) { if(s<num) { num=s; return 1; } } else if(k<n) { if(n-k<=2*k-n) { s+=n-k; if(s<num) num=s; } else { s=s+2*k-n-1; if(s<num) num=s; } return 0; } else { if(k%2==0) { if(chu(s,n,k/2)==1) return 1; } else { if(chu(s,n,k-1)==1) return 1; if(chu(s,n,k+1)==1) return 1; } } return 0; } int main() { long k,n; while(cin>>n>>k) { if(n>k) cout<<n-k<<endl; else { num=10000000; chu(-1,n,k); cout<<num<<endl; } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator