catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个单位,3. 移动到当前位置的二倍处.输出移动的最少次数. 解题思路 使用搜索,准确地说是广搜,要记得到达的位置要进行标记,还有就是减枝. 详情见代码实现. 代码实现 #include<cstdio> #include<cstring> #include<iostream>…
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…
题意:可以把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…
题目链接: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…
链接: 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…
题意:给定农夫和奶牛的初始位置,农夫可以当前位置+1.-1.*2三种移动方式,问最少需要多少分钟抓住奶牛 AC代码: #include<cstdio> #include<cstring> #include<queue> using namespace std; const int maxn=100000+5; const int dx[]={-1,1,2}; int d[maxn]; int n,k; int bfs(){ queue<int>q; mems…
//标准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://ac.nowcoder.com/acm/contest/984/L 来源:牛客网 Catch That Cow 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He sta…
题目链接:http://poj.org/problem?id=3414 思路:bfs简单应用,增对瓶A或者瓶B进行分析就可以了,一共6种状态. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; struct Node{ int a,b,step; ][]; }; int A,B…
The Game 题意: Description One morning, you wake up and think: "I am such a good programmer. Why not make some money?" So you decide to write a computer game. 一天清晨,你起床后想到:"我是一个这么牛的程序员,为什么不赚点钱呢?"所以,你决定写一个电脑游戏. The game takes place on a re…