Zoj 3865 Superbot
按规则移动机器人 , 问是否能拾得宝藏 。
加了一个控制板 , 还增加了一个控制板移动周期 p
将移动周期变换一下 , 移动一次 就相当于光标向左不耗费时间的移动了一格
搜索思路 : 搜索当前格子到上下左右四个格子所花费的最短时间 。
记录光标的信息 , 和当前格子所需最短时间 。
bfs + bfs
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
#define MAXN 20
#define INF 0x3f3f3f3f
int p,min_num;
int n,m;
int G[MAXN][MAXN];
int dir[][]={{,-},{,},{-,},{,}};
struct point
{
int x;
int y;
}start,pos;
struct base
{
int cnt;
int t;
}step[MAXN][MAXN];
int read_ch(int x, int y)
{
char ch;
while(ch = getchar())
{
if(ch == '@')
{
start.x=x;
start.y=y;
return true;
}
if(ch == '.') return true;
if(ch == '$')
{
pos.x=x;
pos.y=y;
return true;
}
if(ch == '*') return false;
}
}
void show()
{
for(int i = ; i <= n ; i ++,cout<<endl)
for(int j = ; j <= m ; j ++)
printf(step[i][j].cnt == INF?"INF ":"%3d ", step[i][j].cnt);
cout<<endl;
}
int bfs(int t,int cnt,int pos)
{
queue <int> Q;
int temp=;
Q.push(cnt);
Q.push(temp);
while(!Q.empty())
{
int x=Q.front();
Q.pop();
temp=Q.front();
Q.pop(); if(((t+temp) % p == ) && (t + temp)) x = (x + ) % ; Q.push((x+)%);
Q.push(temp+); Q.push(x);
Q.push(temp+); Q.push((x+)%);
Q.push(temp+); if(x == pos) return t+temp+;
}
return INF;
}
void _bfs()
{
memset(step,0x3f,sizeof(step));
step[start.x][start.y].cnt=;
step[start.x][start.y].t=;
queue <int> Q;
Q.push(start.x);
Q.push(start.y);
while(!Q.empty())
{
int x = Q.front();
Q.pop();
int y = Q.front();
Q.pop(); if(x < || x > n || y < || y > m || !G[x][y]) continue; for(int i=;i<;i++)
{
int xx = x + dir[i][];
int yy = y + dir[i][]; if(xx < || xx > n || yy < || yy > m || !G[xx][yy]) continue; int temp = bfs(step[x][y].t,step[x][y].cnt,i);
if(temp < step[xx][yy].t)
{
step[xx][yy].t = temp;
step[xx][yy].cnt = i;
Q.push(xx);
Q.push(yy);
//printf("x:%2d y:%2d cnt:%2d xx:%2d yy:%2d \n",x,y,i,xx,yy);
//show();
}
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d %d %d",&n,&m,&p);
memset(G,false,sizeof(G));
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
G[i][j]=read_ch(i,j);
_bfs();
printf(step[pos.x][pos.y].t != INF?"%d\n":"YouBadbad\n",step[pos.x][pos.y].t);
}
return ;
}
Zoj 3865 Superbot的更多相关文章
- BFS+模拟 ZOJ 3865 Superbot
题目传送门 /* BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: BFS分4种情况入队,最后在终点4个方向寻找最小值:) */ #include <cstdio&g ...
- ZOJ 3865 Superbot(优先队列--模板)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 主要思路:1.从一个点(cur)到它相邻的点(next),所需 ...
- zoj.3865.Superbot(bfs + 多维dp)
Superbot Time Limit: 2 Seconds Memory Limit: 65536 KB Superbot is an interesting game which you ...
- ZOJ - 3865 Superbot 【BFS】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3865 思路 一个迷宫题 但是每次的操作数和普通的迷宫题不一样 0 ...
- 浙江大学2015年校赛F题 ZOJ 3865 Superbot BFS 搜索
不知道为什么比赛的时候一直想着用DFS 来写 一直想剪枝结果还是TLE = = 这题数据量不大,又是问最优解,那么一般来说是用 BFS 来写 int commandi[4] = {1, 2, 3, 4 ...
- ZOJ Problem Set - 3865 Superbot (bfs)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 大牛博客:http://www.cnblogs.com/kylehz/p ...
- zoj 3865
Superbot Time Limit: 2 Seconds Memory Limit: 65536 KB Superbot is an interesting game which you ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
随机推荐
- Java-SSI框架学习
框架简介: 相信大家对于mvc的三层架构已经灰常熟悉了,在这就不细讲了,个人感觉ssi的框架结构还是比较典型的mvc三层架构,还是比较容易上手的.关于这块的入门我想特别感谢下FrankHui童鞋,在他 ...
- 程序猿的编程神器 - vim
一.官方文档: 当你首次安装好 Vim 之后.能够用 :help tutor 或者 :help tutor@cn 命令.进入一个30分钟的 Vim 新手教程.你也能够下载一个 Vim Document ...
- FastDFS分布文件系统[转]
FastDFS是为互联网应用量身定做的一套分布式文件存储系统,非常适合用来存储用户图片.视频.文档等文件.对于互联网应用,和其他分布式文件系统相比,优势非常明显.具体情况大家可以看相关的介绍文档,包括 ...
- 关于android各种双卡手机获取imei,imsi的处理(mtk,展讯,高通等)
目前国内对于双卡智能手机的需求还是很大的,各种复杂的业务会涉及到双卡模块:而android标准的api又不提供对双卡的支持.导致国内双卡模块标准混乱,各个厂商各玩各的.目前我知道的双卡解决方案就有:m ...
- 查看LINUX发行商版本与LINUX内核版本
查看LINUX发行商版本:[root@server-mysql ~]# cat /etc/issue Red Hat Enterprise Linux Server release 6.3 (Sant ...
- 去掉cajviewer 右上角的“中国知网数字出版物超市
cajviewer软件是一款可以提取pdf字码的软件(即使pdf是扫描版的) 下面是转的一个博文可以去除软件右上角图标的方法: 去掉cajviewer 7.1.2右上角的“中国知网数字出版物超市” 1 ...
- windows7 'telnet'不是内部或外部命令--转载
['telnet'不是内部或外部命令,也不是可运行的程序或批处理文件]当你想用telnet命令时,发现提示这句话怎么办?其实很简单,接下来为大家介绍下如何使用 方法/步骤 一般只有windows7 ...
- Freemarker学习中遇到的问题
在网上找到了尚学堂的视频,同时有书和源码等资料.但是在跟着练习的过程中,代码运行报了错: 2015-7-20 22:26:40 freemarker.log.JDK14LoggerFactory$JD ...
- site与subsite
1.List template只能加载在主站点上,加载在主站点上之后,其subsite也能引用: 2.发布webpart的时候,路径也只能写网站集的路径,发布到网站集之后其主站点和subsite都能引 ...
- Http协议、线程、线程池
Socket模拟服务端运行代码: 1:启动服务端监听的服务,并接受客户端的连接 1.1 创建Socket Socket listenSocket=new Socket(AddressFamily.In ...