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. bzoj 3142 数学

    找规律后可以之后答案就是 k^(m-1)*(n-(m-1)*k)+(m+(m-1)*k+1)*k^(m-1) div 2 /************************************** ...

  2. hdu 5120 Intersection

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...

  3. SQL Server中存储过程 比 直接运行SQL语句慢的原因

    问题是存储过程的Parameter sniffing     在很多的资料中都描述说SQLSERVER的存储过程较普通的SQL语句有以下优点: 1. 存储过程只在创造时进行编译即可,以后每次执行存储过 ...

  4. Apache CXF实现Web Service(3)——Tomcat容器和不借助Spring的普通Servlet实现JAX-RS(RESTful) web service

    起步 参照这一系列的另外一篇文章: Apache CXF实现Web Service(2)——不借助重量级Web容器和Spring实现一个纯的JAX-RS(RESTful) web service 首先 ...

  5. jQuery1.9.1--attr,prop与val方法源码分析

    这里只介绍这几个方法的源码,这部分引用了一个技巧,钩子对象,用来做兼容fixed的对象,后面也有一些使用.钩子对象具体的兼容细节这里就不详解了. var nodeHook, boolHook, rcl ...

  6. Python Tricks 若干

    赵斌 - APRIL 29, 2015 在 python 代码中可以看到一些常见的 trick,在这里做一个简单的小结. json 字符串格式化 在开发 web 应用的时候经常会用到 json 字符串 ...

  7. JQuery原理及深入解析--转载

    总体架构 jQuery是个出色的javascript库,最近结合它写javascript,看了下源码. 先从整体.全局的看,jQuery的源码几乎都在下面的代码中: (function() { //… ...

  8. HDU4871 Shortest-path tree(树分治)

    好久没做过树分治的题了,对上一次做是在南京赛里跪了一道很裸的树分治题后学的一道,多校的时候没有看这道题,哪怕看了感觉也看不出来是树分治,看出题人给了解题报告里写了树分治就做一下好了. 题意其实就是给你 ...

  9. 单元最短路径算法模板汇总(Dijkstra, BF,SPFA),附链式前向星模板

    一:dijkstra算法时间复杂度,用优先级队列优化的话,O((M+N)logN)求单源最短路径,要求所有边的权值非负.若图中出现权值为负的边,Dijkstra算法就会失效,求出的最短路径就可能是错的 ...

  10. java EE 5 Libraries 删掉后怎么重新导入

    (1)Add Library   中  MyEclipse Libraries (2)输入 java  即可找到 问题解决.