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 Oiprocs at 2010-08-09 22:25:36 on Problem 3278
#include<iostream>
#include<fstream>
#include<queue>
using namespace std;
int N,K;
int p[100000]={0};
int main()
{
	//ifstream cin("data.txt");
	cin>>N>>K;
	queue<int> Q;
	int t=0;
	int temp;
	int count1=1,count2=0;
	Q.push(N);
	while(1)
	{
		t++;
		while(count1--)
		{
			temp=Q.front();
			if (temp+1==K||temp-1==K||temp*2==K)
			{
				cout<<t;
				return 0;
			}
			if(2*temp<=100000&&p[2*temp]==0)
			{
				Q.push(2*temp);
				p[2*temp]=1;
				count2++;
			}
			if(temp+1<=100000&&p[temp+1]==0)
			{
				Q.push(temp+1);
				p[temp+1]=1;
				count2++;
			}
			if(temp-1<=100000&&p[temp-1]==0)
			{
				Q.push(temp-1);
				p[temp-1]=1;
				count2++;
			}
			Q.pop();
		}
		count1=count2;count2=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