bzoj 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛【bfs】
满脑子dp简直魔性
模拟题意bfs转移即可
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int N=200005;
int s,t,d[N];
bool v[N];
queue<int>q;
inline void wk(int x,int y)
{
d[y]=d[x]+1;
if(!v[y])
{
v[y]=1;
q.push(y);
}
}
int main()
{
scanf("%d%d",&s,&t);
for(int i=0;i<=200000;i++)
d[i]=1e9;
v[s]=1,d[s]=0,q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
v[u]=0;
if(u*2<=200000&&d[u*2]>d[u]+1)
wk(u,u*2);
if(u+1<=200000&&d[u+1]>d[u]+1)
wk(u,u+1);
if(u-1>=0&&d[u-1]>d[u]+1)
wk(u,u-1);
}
printf("%d\n",d[t]);
return 0;
}
bzoj 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛【bfs】的更多相关文章
- BZOJ 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛( BFS )
BFS... -------------------------------------------------------------------------------------------- ...
- 【BZOJ】1646: [Usaco2007 Open]Catch That Cow 抓住那只牛(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1646 这一题开始想到的是dfs啊,,但是本机测样例都已经re了... 那么考虑bfs...很巧妙? ...
- BZOJ1646: [Usaco2007 Open]Catch That Cow 抓住那只牛
1646: [Usaco2007 Open]Catch That Cow 抓住那只牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 634 Solved ...
- 2014.6.14模拟赛【bzoj1646】[Usaco2007 Open]Catch That Cow 抓住那只牛
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- 【题解】[Usaco2007 Open]Catch That Cow 抓住那只牛-C++
题目DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her ...
- 抓住那只牛!Catch That Cow POJ-3278 BFS
题目链接:Catch That Cow 题目大意 FJ丢了一头牛,FJ在数轴上位置为n的点,牛在数轴上位置为k的点.FJ一分钟能进行以下三种操作:前进一个单位,后退一个单位,或者传送到坐标为当前位置两 ...
- hdu 2717 Catch That Cow(广搜bfs)
题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...
- 【OpenJ_Bailian - 4001】 Catch That Cow(bfs+优先队列)
Catch That Cow Descriptions: Farmer John has been informed of the location of a fugitive cow and wan ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
随机推荐
- 理解javascript中的Array类型
引子: 从事前端开发有段时间了,个人观点:想在前端开发这条路上走的更远,不仅要学好HTML&HTML5.CSS&CSS3,最重要的就是要学好javascript了.所以打好javasc ...
- 【03】placeholder
placeholder 表单占位符解决方案 Css Code :-moz-placeholder, ::-webkit-input-placeholder{ color: #bfbfbf; } . ...
- ROS 笔记 程序包/节点/topic
官方教程: wiki.ros.org/cn/ROS/tutorials 程序包打创建于编译 创建程序包 在工作空间的src底下,输入如下命令: $ catkin_create_pkg 要创建的包名 依 ...
- python 中文转码 Excel读csv
大家都知道Excel读csv用的是ascii编码,我认为,ascii没有中文,所以这里指的应该是utf-8. 我遇到的问题是这样的,unity项目只能用txt文件,有一堆数据表用txt的文档保存下来了 ...
- 前端开发:CSS3
CSS介绍: CSS能够使页面具有美观一致的效果,并且能够让内容与格式分离,利于扩展 所以,CSS解决了下面两个问题: 1. 将HTML页面的内容与格式分离: 2. 提高web开发的工作效率. CSS ...
- 文件权限设置与http,php的关系
在web服务器上的文件要使用什么权限比较好呢.我开始的时候直接都是777,后台安全部门的同事,通过漏洞把我管理的服务器给搞了.报告到我这里,我才意识到权限的设置不能马虎.环境采用nginx+php,一 ...
- poj —— 1274 The Perfect Stall
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26274 Accepted: 116 ...
- jeecg报错:java.lang.Exception: No runnable methods
具体报错如下 ------------------------------------------------------- T E S T S --------------------------- ...
- laravel notification
mail篇 public function via($notifiable) { return ['mail']; } 1.新建notification类 php artisan make:notif ...
- [TypeScript] Overload a Function with TypeScript’s Overload Signatures
Some functions may have different return types depending on the types of the arguments with which th ...