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 ...
随机推荐
- 【美妙的Python之二】Python初步
美妙的Python之Python起步 简而言之: Python 是能你无限惊喜的语言,与众不同. 1.动态类型: Python是一种动态类型语言,不 ...
- Java大数类介绍
java能处理大数的类有两个高精度大整数BigInteger 和高精度浮点数BigDecimal,这两个类位于java.math包内,要使用它们必须在类前面引用该包:import java.math. ...
- nginx lua 开发笔记
获取 在lua代码中获取 location 正则的参数对应的变量 // location location ~/lua_http_2/(\w*.+) { } // lua local vars=ngx ...
- [TypeScript] Generating Definition Files
TypeScript allows you to generate definition files for your own libraries. This lesson shows you how ...
- 经验总结17--submitbutton,ajax提交
发篇小文章,纪念七七事变. submit一般用于提交表单,可是想使用ajax进行提交,又想按"enter"触发button. 那么就阻止提交表单的事件,进行自己定义的提交. 1.让 ...
- oracle16 例外
例外处理 例外的分类 oracle将例外分为预定义例外,非预定义例外和自定义例外三种. 预定义例外用于处理常见的oracle错误 非预定义例外用于处理预定义例外不能处理的例外 自定义例外用于处理与or ...
- Cocos2d-x中常用粒子编辑器ParticleDesigner测试例子
打开 ParticleDesigner 随意选择一种效果 选择save. 类型选择 cocosd(plist)类型保存至桌面 命名为myplist导出至桌面 选择右侧Emitter Config可设置 ...
- iOS-SQLite数据库使用介绍
iOS-SQLite数据库使用介绍 SQLite是MySQL的简化版,更多的运用与移动设备或小型设备上.SQLite的优点是具有可移植性,它不需要服务器就能运行,同时,它也存在一些缺陷,首先,没有提供 ...
- Java基础知识强化之网络编程笔记03:UDP之UDP协议发送数据 和 接收数据
1. UDP协议发送数据 和 接收数据 UDP协议发送数据: • 创建发送端的Socket对象 • 创建数据,并把数据打包 • 调用Socket对象的发送方法,发送数据包 • 释放资源 UDP协议接 ...
- iTunes无法验证服务器“s.mzstatic.com.”的身份
修改hosts文件,在里面添上一行 23.214.233.166 s.mzstatic.com