按规则移动机器人 , 问是否能拾得宝藏 。

加了一个控制板 , 还增加了一个控制板移动周期 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的更多相关文章

  1. BFS+模拟 ZOJ 3865 Superbot

    题目传送门 /* BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: BFS分4种情况入队,最后在终点4个方向寻找最小值:) */ #include <cstdio&g ...

  2. ZOJ 3865 Superbot(优先队列--模板)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 主要思路:1.从一个点(cur)到它相邻的点(next),所需 ...

  3. zoj.3865.Superbot(bfs + 多维dp)

    Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you ...

  4. ZOJ - 3865 Superbot 【BFS】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3865 思路 一个迷宫题 但是每次的操作数和普通的迷宫题不一样 0 ...

  5. 浙江大学2015年校赛F题 ZOJ 3865 Superbot BFS 搜索

    不知道为什么比赛的时候一直想着用DFS 来写 一直想剪枝结果还是TLE = = 这题数据量不大,又是问最优解,那么一般来说是用 BFS 来写 int commandi[4] = {1, 2, 3, 4 ...

  6. ZOJ Problem Set - 3865 Superbot (bfs)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 大牛博客:http://www.cnblogs.com/kylehz/p ...

  7. zoj 3865

    Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you ...

  8. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  9. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

随机推荐

  1. Office激活密钥

    Retail密钥: PHX9Q-N9GKW-CG4VF-MHCWR-367TX PB44J-GNX2R-BJJYX-HJW6R-Q9JP9 6PVPD-CNWDQ-G734C-DG7BM-VQTXK ...

  2. 使用Pager-taglib进行分页

    在.net中,我们有分页控件.在java中,我们有分页标签库.他们都已经为我们封装好了,我们只需要给这几个参数:数据.当前页码.每页记录数,就能完成分页,所以他们是大同小异的. 今天来说说Pager- ...

  3. linux 上不去网

    linux 上不去网   ip dns无误 ping可以到达网关 可能原因 网卡睡眠 ethtool eht0  //查看eht0网口基本设置 mii-tool -w eth0

  4. ueditor 添加微软雅黑字体 异常“从客户端中检测到有潜在危险的 request.form值”,解决

    使用ueditor往数据库添加文本内容时,如果字体有css样式, <,>," 这些字符会导致报出异常信息:从客户端中检测到有潜在危险的 request.form值 因为这些字符有 ...

  5. fsdfasfsa

    http://www.cnblogs.com/daniel206/archive/2008/01/16/1041729.html using System.IO;using System.Net;us ...

  6. sqlmap

    http://192.168.136.131/sqlmap/mysql/get_int.php?id=1 当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数 2.判断可以用那种SQL注 ...

  7. wordpress密码生成与登录密码验证

    一.研究wordpress时wordpess的密码密码生成与登录密码验证方式很重要 WordPress密码已成为整合的首要目标,如何征服整合,就得了解WordPress密码算法. WordPress系 ...

  8. html input[type=file] css样式美化【转藏】

    相信做前端的都知道了,input[type=file]和其他输入标签不一样,它的事件必须是在触发自身元素上,而不能是其他元素.所以不能简单的把input隐藏,放个button上去. <a hre ...

  9. C# Ref 与out 的区别

    在C#中,有四种传递参数方式: 1. 传值 (value) : 无额外修饰符 2. 传址(reference) : 需修饰符Ref,传入函数的参数必须先赋值 3. 输出参数(output): 需修饰符 ...

  10. Delphi 类方法和普通方法的区别 .

    //类声明  TMyClass = class  public    class procedure MyProc;  //类方式    constructor Create;      //Crea ...