Catch That Cow(POJ3278)(入门)
来源:互联网 发布:mac phpmyadmin 配置 编辑:程序博客网 时间:2024/05/17 20:24
どこでもドア:http://poj.org/problem?id=3278
AC CODE:
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>#include<sstream>#include<set>#include<cstdlib>#include<map>#include<queue>using namespace std;typedef long long LL;const int M= 100000+10;int n,m,ans[M],vis[M];int main(){ int n,m; cin>>n>>m; int x; queue<int>que; que.push(n); ans[n] = 0; while(!que.empty()) { x = que.front(); que.pop(); vis[x] = 1; if (x==m) { cout<<ans[x]<<endl; break; } if (x-1>=0 && vis[x-1]==0) { que.push(x-1); ans[x-1] = ans[x] + 1; vis[x-1] = 1; } if (x+1<100001 && vis[x+1]==0) { que.push(x+1); ans[x+1] = ans[x] + 1; vis[x+1] = 1; } if (x*2<100001 && vis[x*2]==0)//这里判断,&&前后判断颠倒位置(写成vis[x*2]==0&&x*2<100001)就会re,这样就ac。。原因待解。。 { que.push(x*2); ans[x*2] = ans[x] + 1; vis[x*2] = 1; } } return 0;}
0 0
- Catch That Cow(POJ3278)(入门)
- POJ3278 Catch That Cow(BFS入门)
- POJ3278 Catch That Cow BFS入门
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278 - Catch That Cow
- POJ3278 Catch That Cow
- POJ3278--Catch That Cow
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278--Catch That Cow
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- POJ3278,Catch That Cow
- poj3278--Catch That Cow
- POJ3278---Catch That Cow
- poj3278 Catch That Cow
- spring的IoC环境搭建
- gtags运行时报错 input buffer overflow 解决办法
- C语言中的初等数据结构
- leetCode_Patching Array
- 怎么组队打求生之路(局域网中)
- Catch That Cow(POJ3278)(入门)
- uva 11374/Airport Express
- 幻灯片PPT(PowerPoint)绘制的图形如何转为EPS格式
- 409. Longest Palindrome
- getCurrentSession()与openSession()的区别?
- Java之IO详解(一)
- U3D初学:Rigidbody
- 数据的增删改
- sphinx的Coreseek安装