题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数. 坑:标题写了.有点不会写bfs了... ac代码 #define _CRT_SECURE_NO_WARNINGS #include<cstring> #include<cctype> #include<cstdlib> #include<cmath> #include<cstdio> #include<string> #include<stack> #in…
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个单位,3. 移动到当前位置的二倍处.输出移动的最少次数. 解题思路 使用搜索,准确地说是广搜,要记得到达的位置要进行标记,还有就是减枝. 详情见代码实现. 代码实现 #include<cstdio> #include<cstring> #include<iostream>…
链接: http://poj.org/problem?id=3278 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 62113   Accepted: 19441 Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a poi…
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 m…
//标准bfs #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> using namespace std; ] = { , - }; struct node { int x, step; } s, ss; int bfs(int n, int k) { queue<node>q, qq; s.x =…
题目链接:https://vjudge.net/problem/POJ-3278 题意:人可以左移动一格,右移动一格,或者移动到当前位置两倍下标的格子 思路:把题意的三种情况跑bfs,第一个到达目的地的时间最短. #include <iostream> #include <string.h> #include<queue> #include <algorithm> using namespace std; #define rep(i,j,k) for(int…
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…
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…
BFS... -------------------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue>   #define rep( i , n ) for( int i =…
http://www.lydsy.com/JudgeOnline/problem.php?id=1646 这一题开始想到的是dfs啊,,但是本机测样例都已经re了... 那么考虑bfs...很巧妙? 首先我们得确定一个上下界. 当到达距离<0时显然不可能再走了(准确来说绝对不会比当前优),所以这里可以剪枝. 当到达距离>max(n, k)+1时也不能再走了(准确说不会比之前的优,比如说,你走到了k+2,但是之前就可在某个小于k的地方走×2的就走到了,那么就比这个少了1步)所以这里可以剪枝 然后…