抓住那头牛(POJ3278)
题目:
https://cn.vjudge.net/problem/POJ-3278
代码如下:
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
#define MAX 1000005
int step[MAX];
bool vis[MAX];
queue<int> q;
int bfs(int n,int k)
{
int head,next;
q.push(n);
step[n] = 0;//初始位置花费时间0
vis[n] = 0;
while(!q.empty())
{
head = q.front();
q.pop();
for(int i = 0;i < 3;i++)
{
if(i == 0) next = head - 1;
else if(i == 1) next = head + 1;
else if(i == 2) next = head * 2;
if(next < 0 || next >= MAX) continue;
if(vis[next])
{