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)的更多相关文章

  1. zoj.3865.Superbot(bfs + 多维dp)

    Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you ...

  2. 浙江大学2015年校赛F题 ZOJ 3865 Superbot BFS 搜索

    不知道为什么比赛的时候一直想着用DFS 来写 一直想剪枝结果还是TLE = = 这题数据量不大,又是问最优解,那么一般来说是用 BFS 来写 int commandi[4] = {1, 2, 3, 4 ...

  3. BFS+模拟 ZOJ 3865 Superbot

    题目传送门 /* BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: BFS分4种情况入队,最后在终点4个方向寻找最小值:) */ #include <cstdio&g ...

  4. ZOJ Problem Set - 3820 Building Fire Stations 【树的直径 + 操作 】

    题目:problemId=5374" target="_blank">ZOJ Problem Set - 3820 Building Fire Stations 题 ...

  5. ZOJ Problem Set - 3229 Shoot the Bullet 【有上下界网络流+流量输出】

    题目:problemId=3442" target="_blank">ZOJ Problem Set - 3229 Shoot the Bullet 分类:有源有汇 ...

  6. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  7. ZOJ Problem Set - 1025解题报告

    ZOJ Problem Set - 1025 题目分类:基础题 原题地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=10 ...

  8. ZOJ Problem Set - 3829Known Notation(贪心)

    ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...

  9. ZOJ Problem Set - 2563 Long Dominoes 【如压力dp】

    称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 ...

随机推荐

  1. poj 2711 Leapin' Lizards && BZOJ 1066: [SCOI2007]蜥蜴 最大流

    题目链接:http://poj.org/problem?id=2711 题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1066 Your p ...

  2. Android系统Recovery工作原理

    Android系统Recovery工作原理之使用update.zip升级过程分析(一)---update.zip包的制作 http://blog.csdn.net/mu0206mu/article/d ...

  3. CSRF(跨站请求伪造)攻击方式

    一.CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSR ...

  4. Linux 的多线程编程的高效开发经验

    http://www.ibm.com/developerworks/cn/linux/l-cn-mthreadps/ 背景 Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多 ...

  5. 《EnterLib PIAB深入剖析》系列博文汇总_转

    转: http://www.cnblogs.com/artech/archive/2008/08/08/1263418.html

  6. 纯js页面跳转整理

    js方式的页面跳转1.window.location.href方式    <script language="javascript" type="text/java ...

  7. LSTM/RNN的应用Case

    作者:许铁-巡洋舰科技链接:https://www.zhihu.com/question/37082800/answer/126430702来源:知乎著作权归作者所有,转载请联系作者获得授权. 作者: ...

  8. Add and Search Word - Data structure design

    https://leetcode.com/problems/add-and-search-word-data-structure-design/ Design a data structure tha ...

  9. MongoDB 管理工具:Robomongo

    http://www.open-open.com/lib/view/open1383029577546.html

  10. linux下tomcat下部署项目如何打包压缩备份

    范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar[root@linux ~]# tar -cvf /tmp/etc.tar /etc <==仅打包,不压缩![root ...