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. ip地址转化代码实例

    /*@author: lgh@ * * */ #include <stdio.h> #include <string.h> #include <unistd.h> ...

  2. sentinel.conf配置

    1.常用的配置 port 26379 # sentinel announce-ip <ip> # sentinel announce-port <port> dir /tmp ...

  3. Applicationpoolidentity 好有趣哦

    前言: 在服务器上搭建一个网站 Windows Server2008 R2 +IIS7. 应用程序池默认选择ApplicationPoolIdentity.为了适应分布式需求,所以将SqlServer ...

  4. max_flow(Edmond_Karp) 分类: ACM TYPE 2014-09-02 10:47 92人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> #include<queue> usi ...

  5. ios 缓存策略

    NSURLRequestCachePolicy 缓存策略   1> NSURLRequestUseProtocolCachePolicy = 0, 默认的缓存策略, 如果缓存不存在,直接从服务端 ...

  6. 几个Google中国的访问IP

    前面几个IP的访问速度比较快. 74.125.31.106 173.194.45.20 173.194.45.19 173.194.45.18 173.194.45.17 173.194.45.16 ...

  7. Hadoop伪分布模式配置

    本作品由Man_华创作,采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.基于http://www.cnblogs.com/manhua/上的作品创作. 请先按照上一篇文章H ...

  8. 16进制转rgb

    - (void)colorWithHexString: (NSString *) stringToConvert { //去掉前后空格换行符 NSString *cString = [[stringT ...

  9. ExtJS与jQuery的一点细节上的对比

    首先说明这不是一篇完整解读ExtJS和jQuery所有方面差异的文章,只是针对我个人刚看了两天的jQuery产生的一些疑问的整理.之前用过一段时间ExtJS,了解ExtJS的一些机制.现在做移动开发, ...

  10. mybatis处理查询map列表属性为null的问题,而导致查询map无该key对象

    1.常规处理方法(数据库以mysql为例) IFNULL(m.last_use_time,) ) ) as last_lat if判断是否为null,设置一个默认值. 2.前台jsp页面处理,判断是否 ...