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 ...
随机推荐
- Cocos2d-x 在缓存创建图片
/* 加载图片资源到SpriteFrame缓存池*/ CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache( ...
- nginx lua 开发笔记
获取 在lua代码中获取 location 正则的参数对应的变量 // location location ~/lua_http_2/(\w*.+) { } // lua local vars=ngx ...
- PHP汉字转拼音的两种方法+PHP提取汉字(中文)方法
方法一:依据ASCII码转换,GB2312库对多音字也无能为力. GB2312标准共收录6763个汉字,不在范围内的汉字是无法转换.如:中国前总理朱镕基的"镕"字. GB2312中 ...
- mac os 终端提示 you have new mail
这里的信息可能是由于所做的什么操作触发了发邮件的事件, 系统发送的邮件提醒. 我遇到的原因是由于运行 cron , 由于权限所导致了发邮件的事件提醒. Last login: Tue Apr 26 0 ...
- linux tar 压缩解压缩
解压 .tar.bz tar zxvf file.tar.gz .tar.gz2 tar jxvf file.tar.bz2 .bz gzip -d file.bz .gz2 bzip2 -d fil ...
- apache安全之修改或隐藏版本信息
修改apache版本信息 在安装之前,编辑原文件httpd-2.2.31/include/ap_release.h文件如下: 40 #define AP_SERVER_BASEVENDO ...
- in 与 = 的区别
in 与 = 的区别 结果是相同的.
- [Cookie] C#CookieHelper--C#操作Cookie的帮助类 (转载)
点击下载 CookieHelper.rar 下面是代码大家看一下 /// <summary> /// 类说明:CookieHelper /// 联系方式:361983679 /// 更新网 ...
- 关于打开ILDASM的方法
1.通过VisualStudio在开始菜单下的Microsoft Visual Studio 2008/Visual Studio Tools/中的命令提示符中输入ildasm即可 2.将其添加至 ...
- Http请求通信(工具类)
Http请求通信(工具类) 异步消息处理流程是: 首先需要在主线程当中创建一个Handle对象,并重写handlerMessage()方法. 然后当子线程中需要进行UI操作时,就创建一个Message ...