Catch That Cow POJ
来源:互联网 发布:淘宝钻号出售 编辑:程序博客网 时间:2024/05/24 22:42
在
AB坐标<=(N=1e5)
分析:
构建BFS模型。node内保存位置和操作数。
坑点:
没注意 0 也符合题意,设置判断范围时要取 2*N 才合理。
#include <string>#include <cstring>#include <cmath>#include <algorithm>#include <cstdio>#include <queue>#include <iostream>using namespace std;typedef long long ll;typedef pair <int,int> pii;#define mem(s,t) memset(s,t,sizeof(s))#define D(v) cout<<#v<<" "<<v<<endl#define inf 0x3f3f3f3f#define pb push_back//#define LOCALconst int mod=1e9+7;const int MAXN =2e5+10;int n,k;struct node{ node(int X,int c){x=X,cnt=c;} int x,cnt;};int main(){ cin>>n>>k; queue<node> que; que.push(node(n,0)); int vis[MAXN]; mem(vis,0); vis[n]=1; while(!que.empty()){ node t=que.front(); que.pop(); if(t.x==k){ printf("%d\n",t.cnt); break; } if(t.x>=1 && !vis[t.x-1]){ que.push(node(t.x-1,t.cnt+1)); vis[t.x-1]=1; } if(2*t.x<MAXN && !vis[2*t.x]) { que.push(node(2*t.x,t.cnt+1)); vis[2*t.x]=1; } if(t.x+1<MAXN && !vis[t.x+1]){ que.push(node(t.x+1,t.cnt+1)); vis[t.x+1]=1; } } return 0;}
阅读全文
0 0
- Catch That Cow(POJ--
- (poj)Catch That Cow
- Catch That Cow POJ
- Catch That Cow POJ
- Catch That Cow POJ
- Catch That Cow POJ
- Catch That Cow POJ
- Catch That Cow POJ
- poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- poj 3278 catch that cow
- poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- Poj 3278 Catch That Cow
- POJ 3278 Catch That Cow
- POJ 3278 Catch That Cow
- POJ 3278 Catch That Cow
- poj 3278 Catch That Cow
- E185: Cannot find color scheme 'solarized'
- 【BZOJ3282】Tree (Link-Cut Tree)
- Java-static和接口(简述)
- Codeforces Round #441 (Div. 2)-E-National Property(模拟)
- Ireport动态导出pdf,xml
- Catch That Cow POJ
- 个人总结37
- 51Nod 1001
- CCF-训练50题-NO.21-部分A+B
- Spring单例与线程安全小结
- 图论1
- skynet中使用云风的pbc
- mark
- nodeJs与grunt安装与配置