ZOJ Problem Set - 3865 Superbot (bfs)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477
大牛博客:http://www.cnblogs.com/kylehz/p/4420009.html
只不过状态用vis[20][20][4]来记录,每个点都有四个状态,访问过就不能访问
通过控制面板控制机器人找钻石,控制面板每p时间右移一次(队尾变队首),求最短路径
控制面板为左右上下的顺序,初始时 光标在左
有3种操作,占用一个单位时间
1. 光标左移(最左的移到最右)或者右移(最右的移到最左)
2.按按钮,机器人会根据光标所指的方向移动一个单位
3.停在原地
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 500010
using namespace std; int n,m,p;
char mp[][];
bool vis[][][];
int dx[]={,,-,};
int dy[]={-,,,};
struct point
{
int x,y,step,dir;
}ss; point s,e; void bfs()
{
queue<point>q;
s.step=s.dir=;
q.push(s);
while(q.size())
{
point t=q.front();
q.pop();
if(t.x==e.x&&t.y==e.y) //到达目标点
{
printf("%d\n",t.step);
return;
}
if(t.step&&t.step%p==) //光标移动一次
{
t.dir=(t.dir+)%;
}
if(vis[t.x][t.y][t.dir]) continue;
vis[t.x][t.y][t.dir]=true; //标记访问过 s.x=t.x+dx[t.dir]; //往前移动
s.y=t.y+dy[t.dir];
s.step=t.step+;
s.dir=t.dir;
if(s.x>=&&s.x<n&&s.y>=&&s.y<m&&mp[s.x][s.y]!='*')
{
q.push(s);
} s.x=t.x; //原地不动
s.y=t.y;
s.step=t.step+;
s.dir=t.dir;
q.push(s); s.x=t.x; //光标向右移
s.y=t.y;
s.step=t.step+;
s.dir=(t.dir+)%;
q.push(s); s.x=t.x; //光标向左移
s.y=t.y;
s.step=t.step+;
s.dir=(t.dir+)%;
q.push(s);
}
puts("YouBadbad"); //找不到目标点 退出
} int main()
{
//Read();
//Write();
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&p);
for(int i=;i<n;i++)
scanf("%s",mp[i]);
for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
if(mp[i][j]=='@')
{
s.x=i;
s.y=j;
}
if(mp[i][j]=='$')
{
e.x=i;
e.y=j;
}
}
memset(vis,,sizeof(vis));
bfs();
}
return ;
}
ZOJ Problem Set - 3865 Superbot (bfs)的更多相关文章
- zoj.3865.Superbot(bfs + 多维dp)
Superbot Time Limit: 2 Seconds Memory Limit: 65536 KB Superbot is an interesting game which you ...
- 浙江大学2015年校赛F题 ZOJ 3865 Superbot BFS 搜索
不知道为什么比赛的时候一直想着用DFS 来写 一直想剪枝结果还是TLE = = 这题数据量不大,又是问最优解,那么一般来说是用 BFS 来写 int commandi[4] = {1, 2, 3, 4 ...
- BFS+模拟 ZOJ 3865 Superbot
题目传送门 /* BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: BFS分4种情况入队,最后在终点4个方向寻找最小值:) */ #include <cstdio&g ...
- ZOJ Problem Set - 3820 Building Fire Stations 【树的直径 + 操作 】
题目:problemId=5374" target="_blank">ZOJ Problem Set - 3820 Building Fire Stations 题 ...
- ZOJ Problem Set - 3229 Shoot the Bullet 【有上下界网络流+流量输出】
题目:problemId=3442" target="_blank">ZOJ Problem Set - 3229 Shoot the Bullet 分类:有源有汇 ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1025解题报告
ZOJ Problem Set - 1025 题目分类:基础题 原题地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=10 ...
- ZOJ Problem Set - 3829Known Notation(贪心)
ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...
- ZOJ Problem Set - 2563 Long Dominoes 【如压力dp】
称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 ...
随机推荐
- netty 粘包问题处理
netty 粘包问题处理 key words: netty 粘包 解包 半包 TCP 一般TCP粘包/拆包解决办法 定长消息,例如每个报文长度固定,不够补空格 使用回车换行符分割,在包尾加上分割符,例 ...
- 中断(interrupt)、异常(exception)、陷入(trap)
原文出处:http://lhk518.blog.163.com/blog/static/3153998320084263554749/ 中断:是为了设备与CPU之间的通信.典型的有如服务请求,任务完成 ...
- LAMP一键安装包-CentOS 5/6下自动编译安装Apache,MySQL,PHP
http://www.centos.bz/lamp/ 此安装包已经不再维护,请使用新版http://www.centos.bz/ezhttp/. 适用环境: 系统支持:CentOS-5 (32bit/ ...
- xp/2003开关3389指令
开启3389: @echo offtitle 开启3389clsrem 开启3389reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ ...
- 疯狂java讲义——多态
父类 f = new 子类(); 引用变量f,在编译时类型是父类,在运行时类型是子类类型.当这个引用变量调用子类重写父类的那个方法的时候,实际执行的是子类中重写后的那个方法.当运行的时候调用该变量的方 ...
- VMware 进入bios
在虚拟机创建目录中找到.vmx结尾的文件. 添加bios.forceSetupOnce = "TRUE". 打开虚拟机,他会自动进入bios,随后他会把bios.forceSetu ...
- hdu 4767 Bell
思路:矩阵快速幂+中国剩余定理!! 查资料得到2个公式: 1) B[n+p] = B[n] + B[n+1] mod p ; 2) B[p^m+n] = ...
- 李洪强iOS开发之OC[010] - 有参方法的声明实现和调用
// // main.m // 09 - 有参方法的声明实现和调用 // // Created by vic fan on 16/7/5. // Copyright © 2016年 李洪强. ...
- java多线程理解2
1. 什么时候必须同步?什么叫同步?如何同步? 要跨线程维护正确的可见性,只要在几个线程之间共享非 final 变量,就必须使用 synchronized(或 volatile)以确保一个线程可以看见 ...
- android+apimonitor+genymotion
1. 安装genymotion: http://www.genymotion.net/ 2. 设置使用adb Setting--adb--选择sdk的目录 3. apimonitor https:// ...