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> #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator