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 ...
随机推荐
- 【转】Cannot change version of project facet Dynamic Web Module to 3.1 (Eclipse Maven唯一解决方案)
If you want to use version 3.1 you need to use the following schema: http://xmlns.jcp.org/xml/ns/jav ...
- 基于windows的ngnix基础使用
前言 今天组长一大早心血来潮的跟我说,我希望我们小组电脑做web站点的服务器集群,你搞一搞,就用ngnix吧. 君要臣死,臣不得不死.顺便写个文章做个笔记. 简介 Nginx 是一个高性能的HTTP和 ...
- 晕,hibernate 的 merge和cascade="all-delete-orphan"要慎重合在一起使用
遇到一个比较后悔莫及事情,使用了hibernate 的 merge和cascade="all-delete-orphan" ,子表数据被删除了. 1.使用cascade=" ...
- [AngularJS] Error: $location:nobase
In AngularJS 1.3.x, using $locationProvider.html5Mode(ture), will cause a Error:$location:nobase err ...
- linux 提高进程优先级nice+ 进程调度CFS
http://www.cnblogs.com/wang_yb/archive/2012/09/04/2670564.htmlhttp://liwei.life/2016/04/07/linux%E7% ...
- linux 基础学习图解
http://www.cnblogs.com/xiaoluo501395377/category/465892.html
- hadoop错误ERROR namenode.NameNode (NameNode.javamain(1657)) - Failed to start namenode java.net.BindException:Port in use:host1:50070
解决方法: 1.通过lsof -i:50070(lsof可以通过yum install lsof安装)查看,发现是mysql被占用了 2.修改mysql端口 从/usr/share/mysql/my- ...
- C++使用Json作为数据包装格式的通信
出处:http://adebugger.cn/2009/11/cpp-json-data-communication/ http://hi.baidu.com/tibelf/item/6be2accd ...
- NDK开发之获得域和方法描述符
在NDK开发之调用方法和NDK开发之访问域两篇博客中,我们在获得域ID和方法ID时都需要一个叫做描述符的参数,那么在实际开发中我们怎么知道我们要调用的域或者方法的描述符呢? 一个简单的方法就是使用Ja ...
- javascript split() 正则表达式
路由匹配 http.createServer(function(req, res) { var items = req.url.split('/'); if (items.length < 3 ...