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

请高手帮忙测试一下,指出哪组数据此程序运行结果是错误的!!!!

Posted by gjx2008 at 2007-07-22 21:14:35 on Problem 3278
/*#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:
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