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的.比較火.链接:这里 ...
随机推荐
- JS判断用户是否在线的方法
在以前坐项目的时候,经常碰见通过sessionLisnter来判断用户是否在线的方法,但是由于用户关闭浏览器时不会立刻是否session,因此大部分时候都考虑在页面中通过JS来监控页面是否关闭. 网络 ...
- ExtJS登陆页面涉及到的几个问题
1.如何在文本框中增加提示信息 输入框中无法直接使用tooltip,需要使用单独的代码 var tip = Ext.create('Ext.tip.ToolTip', { target : ...
- Leetcode#76 Minimum Window Substring
原题地址 用两个指针分别记录窗口的左右边界,移动指针时忽略那些出现在S种但是没有出现在T中的字符 1. 扩展窗口.向右移动右指针,当窗口内的字符即将多于T内的字符时,停止右移 2. 收缩窗口.向右调整 ...
- /MT /MD /ML /MTd /MDd /MLd 的区别
Multithreaded Libraries Performance The single-threaded CRT is no longer ( in vs2005 ) available. Th ...
- Spring.net Could not load type from string value
最近有点懒了啊,都没有按时上来博客园更新下,个人觉得遇到难题的时候在这里留下脚印也亦造福他人,进来 晓镜水月 被项目围的团团转,asp.net MVC项目来的,但是我还是不务正业啊,在弄网络爬虫,这个 ...
- 查看w3wp进程占用的内存及.NET内存泄露,死锁分析--转载
一 基础知识 在分析之前,先上一张图: 从上面可以看到,这个w3wp进程占用了376M内存,启动了54个线程. 在使用windbg查看之前,看到的进程含有 *32 字样,意思是在64位机器上已32位方 ...
- sqlite函数大全
abs(X) 返回参数X的绝对值. coalesce(X,Y,...) 返回第一个非空参数的副本.若所有的参数均为NULL,返回NULL.至少2个参数. glob(X,Y) 用于实现SQLite的 ...
- Codeforces 475D CGCDSSQ(分治)
题意:给你一个序列a[i],对于每个询问xi,求出有多少个(l,r)对使得gcd(al,al+1...ar)=xi. 表面上是询问,其实只要处理出每个可能的gcd有多少个就好了,当左端点固定的时候,随 ...
- 整数划分 Integer Partition(二)
本文是整数划分的第二节,主要介绍整数划分的一些性质. 一 先来弥补一下上一篇文章的遗留问题:要求我们所取的 (n=m1+m2+...+mi )中 m1 m2 ... mi连续,比如5=1+4就不符合 ...
- ios图片拉伸两种方法
UIImage *image = [UIImage imageNamed:@"qq"]; 第一种: // 左端盖宽度 NSInteger leftCapWidth = image. ...