SDUT 1028 Catch That Cow
来源:互联网 发布:编程游戏 编辑:程序博客网 时间:2024/06/14 19:29
点击打开题目链接
#include <bits/stdc++.h>using namespace std;struct node{ int data; int sum;};int s, k;queue<node *>Q;void BFS(int st);bool vis[200010];int main(){ cin >> s >> k; memset(vis, 0, sizeof(vis)); node *tmp = new node; tmp -> data = s; tmp -> sum =0; Q.push(tmp); vis[s] = 1; BFS(s); return 0;}void BFS(int st){ int sum, x; while(!Q.empty()) { node *tmp = Q.front(); Q.pop(); x = tmp -> data; sum = tmp -> sum; if(x == k) { cout << sum << endl; return; } if(!vis[x-1]&& x > 0) { node *tmp = new node; vis[x-1] = 1; tmp -> data = x-1; tmp -> sum = sum+1; Q.push(tmp); } if(x <= k && !vis[x+1]) { node *tmp = new node; vis[x+1] = 1; tmp -> data = x+1; tmp-> sum = sum+1; Q.push(tmp); } if(x <= k && !vis[x*2]) { node *tmp = new node; vis[x*2] = 1; tmp -> data = x*2; tmp -> sum = sum+1; Q.push(tmp); } }}
0 0
- Catch That Cow SDUT 1028
- SDUT 1028 Catch That Cow
- SDUT-Catch That Cow
- SDUT 1028 Catch That Cow (BFS)
- SDUT OJ 1028 Catch That Cow
- sdut 1028 Catch That Cow( BFS)
- sdut oj1208 Catch That Cow(BFS)
- SDUToj 1028 Catch That Cow (BFS)
- (bfs)1028Catch That Cow
- POJ3278 Catch That Cow
- Catch That Cow
- Catch That Cow
- poj3278 Catch That Cow
- 3278. Catch That Cow
- 【HDU2717】-Catch that cow
- Catch That Cow
- F - Catch That Cow
- poj3278 - Catch That Cow
- <LeetCode> 题439:线段树的构造(2)
- NIO实战(一)——文本文件的按行读取
- vim(Linux编辑器)的使用
- 迪杰斯科拉算法
- 数学基础 —— 向量基础(一)
- SDUT 1028 Catch That Cow
- 985的买饮料难题
- 将centos 7 自带的 php 5.4升级为 5.6
- Mysql主从概述
- 操作系统原理——自学笔记
- Java并发编程:Lock
- Ubuntu下配置Hue的各种问题
- show master logs;
- <LeetCode> 题202:线段树的查询