catch the cow(简单题)
来源:互联网 发布:python如何做抢票软件 编辑:程序博客网 时间:2024/05/22 17:03
题目链接:点击打开链接
代码:
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;#include<queue>struct qq{ int x,y;} w;queue<qq >q;int k;int e[200010];void dfs(int n){ w.x=n; w.y=0; while(!q.empty()) { q.pop(); } q.push(w); while(!q.empty()) { qq n1=q.front(); q.pop(); for(int i=0; i<3; i++) { qq n2; if(i==0) n2.x=n1.x*2; else if(i==1) n2.x=n1.x-1; else n2.x=n1.x+1; if(n2.x<0||n2.x>100000||e[n2.x]) continue; n2.y=n1.y+1; e[n2.x]=1; if(n2.x==k) { printf("%d\n",n2.y); return ; } q.push(n2); } } return ;}int main(){ int n; scanf("%d%d",&n,&k); if(n==k) printf("0\n"); else if(n>k) printf("%d\n",n-k); else { memset(e,0,sizeof(e)); e[n]=1; dfs(n); } return 0;}
简单题
0 0
- catch the cow(简单题)
- toj2825 catch the cow BFS典型题
- 重做catch the cow
- Catch The Cow
- catch the cow (P3278)
- HLG Catch The Cow
- openjudge2971 catch the cow
- hdu2717 Catch That Cow BFS简单题
- POJ 3278 Catch The Cow
- poj 3278 catch the cow
- Catch That Cow 简单BFS
- Catch That Cow(简单BFS)
- catch the cow 抓住小黄牛
- POJ-3278 Catch the cow(BFS)
- catch the cow(poj-3728)
- wikioi2966 Catch That Cow 简单BFS
- POJ3278 Catch That Cow 简单BFS
- 简单广搜:Catch That Cow
- NYOJ 1103 区域赛系列一多边形划分(卡特兰数)
- Pixhawk开发环境搭建之PX4固件编译
- 说上一说话
- 51nod 1049 最大子段和
- Spark算子总结及案例
- catch the cow(简单题)
- 368. Largest Divisible Subset
- xcode 卡顿问题
- 基于原生JavaScript进行扩展模拟用户长按事件(webapp)
- 9 signaling at the nerve-muscle synapse: directly gated transmission
- Oracle to_char格式化函数
- ubuntu安装配置FTP
- 51nod 1050 循环数组最大子段和
- jQuery的each、siblings的基本使用和jQ常见错误