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 immediately. He starts at a point N (0 <= N <= 100,000) on a number line and the cow is at a point K (0 <= K <= 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting. * Walking: FJ can move from any point X to the points X-1 or X+1 in a single minute * Teleporting: FJ can move from any point X to the point 2*X in a single minute. If the cow, unaware of its pursuit, does not move at all, how long does it take for Farmer John to retrieve it?
Input
* Line 1: Two space-separated integers: N and K
Output
* Line 1: The least amount of time, in minutes, it takes for Farmer John to catch the fugitive cow.
Sample Input
Farmer John starts at point 5 and the fugitive cow is at point 17.
Sample Output
OUTPUT DETAILS:
The fastest way for Farmer John to reach the fugitive cow is to
move along the following path: 5-10-9-18-17, which takes 4 minutes.
好裸的bfs……n的规模才10w
原来还想的是二进制dp,结果发现我在没事找事……
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,head,tail=1;
int dist[500001];
int q[500001];
inline bool mark(int x)
{
return !(x<0||x>max(2*m+1,n+1));
}
int main()
{
freopen("catchcow.in","r",stdin);
freopen("catchcow.out","w",stdout);
scanf("%d%d",&n,&m);
memset(dist,-1,sizeof(dist));
q[1]=n;dist[n]=0;
while (head<tail)
{
head++;
int now=q[head]-1;
if(mark(now)&&dist[now]==-1)
{
q[++tail]=now;
dist[now]=dist[q[head]]+1;
}
now=q[head]+1;
if(mark(now)&&dist[now]==-1)
{
q[++tail]=now;
dist[now]=dist[q[head]]+1;
}
now=q[head]*2;
if(mark(now)&&dist[now]==-1)
{
q[++tail]=now;
dist[now]=dist[q[head]]+1;
}
if(dist[m]!=-1) {printf("%d",dist[m]);return 0;}
}
}
2014.6.14模拟赛【bzoj1646】[Usaco2007 Open]Catch That Cow 抓住那只牛的更多相关文章
- BZOJ1646: [Usaco2007 Open]Catch That Cow 抓住那只牛
1646: [Usaco2007 Open]Catch That Cow 抓住那只牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 634 Solved ...
- BZOJ 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛( BFS )
BFS... -------------------------------------------------------------------------------------------- ...
- bzoj 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛【bfs】
满脑子dp简直魔性 模拟题意bfs转移即可 #include<iostream> #include<cstdio> #include<queue> using na ...
- 【BZOJ】1646: [Usaco2007 Open]Catch That Cow 抓住那只牛(bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1646 这一题开始想到的是dfs啊,,但是本机测样例都已经re了... 那么考虑bfs...很巧妙? ...
- 【题解】[Usaco2007 Open]Catch That Cow 抓住那只牛-C++
题目DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her ...
- 2014.6.14模拟赛【bzoj1592】[Usaco2008 Feb]Making the Grade 路面修整
Description FJ打算好好修一下农场中某条凹凸不平的土路.按奶牛们的要求,修好后的路面高度应当单调上升或单调下降,也就是说,高度上升与高度下降的路段不能同时出现在修好的路中. 整条路被分成了 ...
- 2014.7.8模拟赛【笨笨当粉刷匠】|bzoj1296 [SCOI]粉刷匠
笨笨太好玩了,农田荒芜了,彩奖用光了,笨笨只好到处找工作,笨笨找到了一份粉刷匠的工作.笨笨有n条木板需要被粉刷.每条木板被分成m个格子,每个格子要被刷成红色或蓝色.笨笨每次粉刷,只能选择一条木板上一段 ...
- 东方14模拟赛之noip2015/day1/3/神奇的幻方
总时间限制: 10000ms 单个测试点时间限制: 1000ms 内存限制: 128000kB 描述 幻方是一种很神奇的N*N 矩阵:它由数字 1,2,3, … …,N*N 构成,且每行.每列及 ...
- 2014.7.7 模拟赛【小K的农场】
3.小K的农场(farm.pas/cpp/c) [题目描述] 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三 ...
随机推荐
- JScript_Test
Hello SyntaxHighlighter function helloSyntaxHighlighter() { return "hi!"; } function hello ...
- wsdl文件结构分析
WSDL (Web Services Description Language,Web服务描述语言)是一种XML Application,他将Web服务描述定义为一组服务访问点,客户端可以通过这些服务 ...
- C#委托与事件之观察者Observer设计模式
前言 委托: 委托是一种在对象里保存方法引用的类型,同时也是一种类型安全的函数指针. 或委托可以看成一种表示函数的数据类型,类似函数指针. 事件是特殊的委托 观察者模式:两种角色:(1)Subj ...
- Lenovo k860i 移植Android 4.4 cm11进度记录【下篇--实时更新中】
2014.8.24 k860i的cm11的移植在中断了近两三个月之后又開始继续了,进度记录的日志上一篇已经没什么写的了,就完结掉它吧,又一次开一篇日志做下篇好了.近期的战况是,在scue同学的努力之下 ...
- 一年后重翻javascript
回想下自己的工作历程 一年多的ios开发眨眼间就过去了 不过这一切还没有结束,紧随其后的便是前段开发,虽然顶点基础都没有,但是还是通过我的不懈努力最终成功转型,虽然刚开始是通过jq直接入门的 ...
- css3圈圈进度条
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 规约模式(Specification Pattern)
前期准备之规约模式(Specification Pattern) 一.前言 在专题二中已经应用DDD和SOA的思想简单构建了一个网上书店的网站,接下来的专题中将会对该网站补充更多的DDD的内容.本专题 ...
- 在同个类中non-const插入const来减少重复
class A { private: std::string a; public: A(std::string b) :a(b){} const char& operator[](int b) ...
- Centos6.5使用yum安装MariaDB
系统版本:Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x8 ...
- Mysql启动失败 MYSQL:The server quit without updating PID file
MySQL5.6启动时出错 提示MYSQL:The server quit without updating PID file 首先执行 /bin/mysqld_safe --user=mysql & ...