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编程那些事(牛客网 LeetCode)
计算给定数组 arr 中所有元素的总和 本人提供常规方法 function sum(arr) { var len = arr.length; var sum = 0; if(len == 0){ su ...
- Fiddler简介与Web抓包,远程抓包(IE、360、谷歌、火狐)
Fiddler简介以及web抓包 一.Fiddler简介 简单来说,Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯.网上简介很多,我们不多说. 二 ...
- myeclipse通过数据表生成jpa或hibernate实体---https://blog.csdn.net/partner4java/article/details/8560289
myeclipse通过数据表生成jpa或hibernate实体-----https://blog.csdn.net/partner4java/article/details/8560289
- 添物不花钱学JavaEE(基础篇)- Tomcat
Tomcat是大家常用的Java Web容器. 添物网使用的也是Tomcat. 官方网址: http://tomcat.apache.org/ 官方文档看看. 可以看的图书 <Tomcat权威指 ...
- pdf & watermark & puppeteer
pdf & watermark & puppeteer background image https://en.wikipedia.org/wiki/Watermark pdf &am ...
- noip模拟赛 斐波那契
分析:暴力分有90,真良心啊. a,b这么大,连图都建不出来,肯定是有一个规律.把每个点的父节点写出来:0 1 1 12 123 12345 12345678,可以发现每一个循环的长度刚好是斐波那契数 ...
- 常见问题:Linux安装Python3步骤、Windows无法利用pip
Linux安装python3.6和第三方库的步骤: 我的Linux是CentOS 6.5版本 Linux下大部分系统默认自带python2.x的版本,最常见的是python2.6或python2.7, ...
- [K/3Cloud] 使用操作还是服务
现在菜单点击事件既可以挂操作又可以挂服务,那到底是应该挂操作还是服务呢? 有个需求是要求一个动作可以在两个时点被触发 1.单据由下推或选单生成的时候: 2.点击单据界面功能菜单: 这样是不是需要做一个 ...
- jquery如何通过ajax请求获取后台数据显示在表格上
1.引入bootstrap和jquery的cdn <link rel="stylesheet" type="text/css" href="ht ...
- 对付 MySQL 的死连接,Sleep的进程的来源探究[转]
当前的连接数:mysql> show status like '%Threads_connected%';+-------------------+-------+| Variable_name ...