poj 3278 搜索】的更多相关文章

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 t…
POJ 3278 Catch That Cow 题目:你要去抓一头牛,给出你所在的坐标和牛所在的坐标,移动方式有两种:要么前一步或者后一步,要么移动到现在所在坐标的两倍,两种方式都要花费一分钟,问你最小花费时间恰好到达牛所在的地方. 思路:BFS求最优解,移动有三种情况,前后,和移动两倍位置,不过注意的地方是,当牛的坐标比你小,你只能一步步往后倒退,这个需要特判. #include<cstdio> #include<cmath> #include<cstring> #i…
题目传送门 /* BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 */ #include <cstdio> #include <iostream> #include <algorithm> #include <map> #include <queue> #include <set> #include <cmath> #include <cstring> using namespace std…
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…
Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 46715   Accepted: 14673 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,00…
题意: 0到N的数轴上,每次可以选择移动到x-1,x+1,2*x,问从n移动到k的最少步数. 思路: 同时遍历三种可能并记忆化入队即可. Tips: n大于等于k时最短步数为n-k. 在移动的过程中可能会越界.重复访问. poj不支持<bits/stdc++.h>和基于范围的for循环. #include <iostream> #include <queue> using namespace std; const int M=110000; struct P{int x…
农夫在x位置,下一秒可以到x-1, x+1, 2x,问最少多少步可以到k *解法:最少步数bfs 要注意的细节蛮多的,写在注释里了 #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; queue<int> q; ], arr[]; void go(int n, int k) { q.push(n); vis[n…
题目链接: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…
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…