Catch That Cow POJ - 3278 bfs map超时,短路判断顺序。
题意:可以把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>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
const int maxn = 1e5 + ;
int vis[maxn];
struct node {
int x, t;
node(int n = , int k = ) :x(n), t(k) {}
}; int n, k;
bool check(int x) {
if ( x > 1e5 || x < || vis[x])return ;
else return ;
}
void Run() {
queue<node> Q;
Q.push(node(n,));
vis[n] = ;
while (!Q.empty()) {
node now = Q.front();
Q.pop(); if (now.x == k) { cout << now.t; break; }
if (check(now.x + ))Q.push(node(now.x + , now.t + )),vis[now.x + ] = ;
if (check(now.x - ))Q.push(node(now.x - , now.t + )), vis[now.x - ] = ;
if (check(now.x * ))Q.push(node(now.x * , now.t + )), vis[now.x * ] = ; }
} void smain() { cin >> n >> k; Run(); }
Catch That Cow POJ - 3278 bfs map超时,短路判断顺序。的更多相关文章
- catch that cow POJ 3278 搜索
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...
- (广搜)Catch That Cow -- poj -- 3278
链接: http://poj.org/problem?id=3278 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6211 ...
- Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- C - Catch That Cow POJ - 3278
//标准bfs #include <iostream> #include <cstdio> #include <algorithm> #include <cm ...
- kuangbin专题 专题一 简单搜索 Catch That Cow POJ - 3278
题目链接:https://vjudge.net/problem/POJ-3278 题意:人可以左移动一格,右移动一格,或者移动到当前位置两倍下标的格子 思路:把题意的三种情况跑bfs,第一个到达目的地 ...
- hdu 2717 Catch That Cow(广搜bfs)
题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...
- POJ 3278 Catch That Cow(模板——BFS)
题目链接:http://poj.org/problem?id=3278 Description Farmer John has been informed of the location of a f ...
- Catch That Cow (简单BFS+剪枝)
Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...
- POJ:3259-Wormholes(最短路判断负环)
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 58153 Accepted: 21747 Descripti ...
随机推荐
- [svc]sort-uniq
uniq - report or omit repeated lines sort -r -t uniq -r -c uniq的作用: 去除相邻重复行 [root@n1 data]# cat ip.t ...
- 【Big Data - Hadoop - MapReduce】hadoop 学习笔记:MapReduce框架详解
开始聊MapReduce,MapReduce是Hadoop的计算框架,我学Hadoop是从Hive开始入手,再到hdfs,当我学习hdfs时候,就感觉到hdfs和mapreduce关系的紧密.这个可能 ...
- Badboy教程
Badboy教程 摘自:Badboy-系列教程-资料整理 2016-11-30 1 界面介绍 2 录制 3 创建suites,tests,steps和Template 4 运行脚本 5 参数化 Add ...
- ESXi创建磁盘命令
[root@esx421 SAN]# vmkfstools -d thick -a lsilogic -c 10G lun00.vmdk Incorrect disk option "thi ...
- ADO.NET 数据库备份等操作
public class SqlServerBackup { private string database; private string server; private string uid; p ...
- Foxpro数据库连接错误解决方法--【VFP DBF文件不是一个有效的路径。 确定路径名称拼写是否正确,以及是否连接到文件存放的服务器】
直接访问vfp dbf文件时报错: 错误描述: 'd:\vfpData\test.dbf'不是一个有效的路径. 确定路径名称拼写是否正确,以及是否连接到文件存放的服务器. 解决办法:Data Sour ...
- Mysql 查询decimal 引号‘’增加精度
sql 通过decimal条件查询添加和不添加引号的区别 SELECT * FROM meta_variable WHERE DataTableID = 123456 # decimal类型 AND ...
- [Cubieboard] 安装 Lubuntu server for SDCard
硬件:Cubieboard2 系统:Ubuntu 14.04 based on VMware Virtual Machine 镜像:cb2-lubuntu-server-tsd-tfcard-v2.0 ...
- python通过get,post方式发送http请求和接收http响应的方法,pythonget
python通过get,post方式发送http请求和接收http响应的方法,pythonget 本文实例讲述了python通过get,post方式发送http请求和接收http响应的方法.分享给大家 ...
- Android 信号处理面面观 之 信号定义、行为和来源
总结: Android中: Sending signal. PID: XXX SIG: 3 ====>打印trace 原文:http://blog.csdn.net/rambo2188/ar ...