1646: [Usaco2007 Open]Catch That Cow 抓住那只牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 634  Solved: 310[Submit][Status] Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a p…
BFS... -------------------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue>   #define rep( i , n ) for( int i =…
题目DescriptionFarmer 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 lin…
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…
http://www.lydsy.com/JudgeOnline/problem.php?id=1646 这一题开始想到的是dfs啊,,但是本机测样例都已经re了... 那么考虑bfs...很巧妙? 首先我们得确定一个上下界. 当到达距离<0时显然不可能再走了(准确来说绝对不会比当前优),所以这里可以剪枝. 当到达距离>max(n, k)+1时也不能再走了(准确说不会比之前的优,比如说,你走到了k+2,但是之前就可在某个小于k的地方走×2的就走到了,那么就比这个少了1步)所以这里可以剪枝 然后…
满脑子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); } }…
题目链接:Catch That Cow 题目大意 FJ丢了一头牛,FJ在数轴上位置为n的点,牛在数轴上位置为k的点.FJ一分钟能进行以下三种操作:前进一个单位,后退一个单位,或者传送到坐标为当前位置两倍的地方.求FJ能找到牛的最短时间. 思路 BFS.在每一个点有三种选择,前进,后退,或者传送.要注意的是,由于有后退的过程,所以可能会造成环,导致队列长度很长就直接MLE了.因此要用一个vis数组来控制不能选择已经去过的地方. 题解 #include <iostream> #include &l…
传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25290 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 ≤ 10…
第一篇博客,格式惨不忍睹.首先感谢一下鼓励我写博客的大佬@Titordong其次就是感谢一群大佬激励我不断前行@Chunibyo@Tiancfq因为室友tanty强烈要求出现,附上他的名字. Catch That Cow(POJ3278) BFS入门题,然鹅我还是WA了四五发,因为没注意,位置0是可以访问的.再者就是初始位置在push之后,要标记为已经访问. 图片挺不错,我们地大(武汉)的旖旎风光,放松一下. 题目链接:POJ3278 Description Farmer John has be…
POJ 3278 Catch That Cow(赶牛行动) Time Limit: 1000MS    Memory Limit: 65536K 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…