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 ...
随机推荐
- Android渲染器Shader:LinearGradient(一)
Android渲染器Shader:LinearGradient(一) LinearGradient是Android的线性渲染器.我写5个LinearGradient渲染器渲染后的View表现结果 ...
- PyUV: Python高性能网络库
libUV的python版本 https://github.com/saghul/pyuv
- 转载:C/C++检测内存泄漏的工具 vld Visual Leak Detector223 的使用方法和sample示例
这类的工具有 比如 :LeakDiag leakfinder "Visual Leak Detector" vld可以从http://vld.codeplex.com/releas ...
- centos7 host修改
首先要说明,hostname和hosts文件没有必然联系,有不明白的同学可以先自行查阅资料了解hostname和hosts文件的关系.这里简要说明一下. hosts文件是dns服务的前身,网络刚开始出 ...
- [bzoj1031][JSOI2007]字符加密Cipher_后缀数组
字符加密Cipher bzoj-1031 JSOI-2007 题目大意:题目链接. 注释:略. 想法: 后缀数组裸题啊. 后缀数组其实背下来板子之后有几个数组记住就可以了. $sa_i$表示排名为$i ...
- bzoj——3555: [Ctsc2014]企鹅QQ
3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 2617 Solved: 921[Submit][Statu ...
- 在 Oracle Linux 上使用 DTrace
作者:Richard Friedman 简要介绍适用于 Oracle Linux 的 DTrace 探测器和提供程序,以及与 Oracle Solaris 中 DTrace 探测器和提供程序的区别.还 ...
- spring mvc 访问静态资源404
访问比如css js出现404提示 在spring的配置文件中加上如下代码即可 <!-- 静态资源404 --> <mvc:resources location="/res ...
- [Algorithms] Insertion sort algorithm using TypeScript
Insertion sort is a very intuitive algorithm as humans use this pattern naturally when sorting cards ...
- HDU 5371 Manacher
点击打开链接 题意:给定一串数字.求最长的一段连续的数字,将它平均分为三段.满足第一段和第二段是回文的.第一段和第三段相等 思路:第一段和第二段是回文的.那么第二段和第三段也是回文的,将数列进行Man ...