1209:Catch That Cow(bfs)
来源:互联网 发布:windows rmdir命令 编辑:程序博客网 时间:2024/06/03 22:55
题意:
从一个坐标到另一个坐标的移动方式有三种,即:st-1,st+1,2*st。每移动一步时间是一秒。
给出两个坐标,求得从第一坐标到第二座标的最短时间。
#include<iostream>#include<cstdio>#include<queue>#include<cstring>using namespace std;const int maxn=100005;int step[maxn];int st,ed;void bfs(){ int key,t; queue<int>que; que.push(st); while(!que.empty()){ key=que.front(); que.pop(); if(key==ed) break; t=key+1; if(t<maxn&&step[t]==0){ step[t]=step[key]+1; que.push(t); } t=key-1; if(0<=t&&t<maxn&&step[t]==0){ step[t]=step[key]+1; que.push(t); } t=key*2; if(t<maxn&&step[t]==0){ step[t]=step[key]+1; que.push(t); } }}int main (){ scanf("%d%d",&st,&ed); memset(step,0,sizeof(step)); bfs(); printf("%d\n",step[ed]); return 0;}
0 0
- 1209:Catch That Cow(bfs)
- Catch That Cow(bfs)
- Catch That Cow+BFS
- Catch That Cow BFS
- Catch That Cow BFS
- Catch That Cow(BFS)
- Catch That Cow BFS
- Catch That Cow (BFS)
- Catch That Cow【bfs】
- Catch That Cow(bfs)
- Catch That Cow BFS
- bfs-catch that cow
- Catch That Cow(bfs)
- Catch That Cow bfs
- Catch That Cow (BFS)
- Catch That Cow --bfs
- Catch That Cow(BFS)
- Catch That Cow 简单BFS
- libxx.so has text relocations. This is wasting memory and prevents security hardening. Please fix
- leetcode——7—— Reverse Integer可仿溢出
- Erlang入门
- SVN状态详解
- #pragma once与#ifndef两种防止头文件二次编译的区别
- 1209:Catch That Cow(bfs)
- mfc获取实时网速的头文件及cpp
- Cocos2dx项目--动作类游戏内存优化--Spine结构分析1
- 40.leetcode题目:
- CreateUDPServer
- iOS笔记_01_UIView初见
- FTP站点+FTP相关问题集
- [IMX6Q][Android5.1]移植笔记 --- LCD显示移植(LVDS接口)
- EGLImage in SurfaceFlinger