| ||||||||||
| 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 | |||||||||
本地各种测试case各种过,提上去就是WA....求助!!//#include "stdafx.h"
#include <stdio.h>
struct Node
{
int num;
struct Node *pre;
}mNodeList[200002];
int N,K;
int index=1,count=1,temp,steps=0;
void BFS()
{
int map[200002]={0};
struct Node firstNode,mNodeLeft,mNodeRight,mNodeDouble;
firstNode.num = N;
firstNode.pre = NULL;
mNodeList[1] = firstNode;
map[N] = -1;
do
{
mNodeLeft.num = mNodeList[index].num-1;
mNodeLeft.pre = &mNodeList[index];
mNodeRight.num = mNodeList[index].num+1;
mNodeRight.pre = &mNodeList[index];
mNodeDouble.num = mNodeList[index].num*2;
mNodeDouble.pre = &mNodeList[index];
if(mNodeDouble.num <=200000 && map[mNodeDouble.num] != -1)
{
mNodeList[++count] = mNodeDouble;
map[mNodeDouble.num] = -1;
}
if(mNodeRight.num <=100000 && map[mNodeRight.num] != -1)
{
mNodeList[++count] = mNodeRight;
map[mNodeRight.num] = -1;
}
if(mNodeLeft.num>=0 && map[mNodeLeft.num] != -1)
{
mNodeList[++count] = mNodeLeft;
map[mNodeLeft.num] = -1;
}
index++;
}while(mNodeLeft.num!=K&&mNodeRight.num!=K&&mNodeDouble.num!=K);
if(mNodeLeft.num == K)
{
temp = count-2;
}else if(mNodeRight.num == K)
{
temp = count-1;
}else
temp = count;
struct Node tempNode;
tempNode = mNodeList[temp];
while(tempNode.pre != NULL)
{
tempNode = *tempNode.pre;
steps++;
}
if(N>=K)
printf("%d\n",N-K);
else
printf("%d\n",steps);
}
int main()
{
while(scanf("%d%d", &N, &K) != EOF)
{
index=1;count=1;temp=0;steps=0;
BFS();
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator