Problem A: The Monocycle
题意:题目意思比较绕,就是给出图,从起点'S'出发,到终点'T',有这样的车轮:车轮每转90度,时间加1,上面的均匀5个扇形,从起点开始,是blue色扇形着地,方向向‘上’,然后求出从起点到终点的最后终点是blue扇形着地的最小时间。
题解:用BFS,counts【x】【y】【dir】【co】表示到达x,y时候方向为dir,颜色是co的最小步数,然后就可以BFS。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define INF 1000000000
using namespace std;
const int N=;
struct Node{
int x;
int y;
int step;
int dir;
int color;
};
int n,m;
char map[N][N];
int counts[N][N][N][N];
int sx,sy;
int ex,ey;
void BFS(int x,int y,int d,int color){//0是北1是西2是南3是东 0是绿色,1是白2蓝3红4黑
queue<Node>Q;
Node temp;
temp.x=x;
temp.y=y;
temp.dir=d;
temp.color=color;
temp.step=;
for(int i=;i<=;i++)
for(int j=;j<=;j++)
for(int k=;k<=;k++)
for(int g=;g<=;g++)
counts[i][j][k][g]=INF;
Q.push(temp);
counts[x][y][d][color]=;
int dir[][]={{-,},{,-},{,},{,}};
while(!Q.empty()){
Node tt=Q.front();
Q.pop();
int xx=tt.x;
int yy=tt.y;
int step=tt.step;
int dd=tt.dir;
int co=tt.color;
if(step+<counts[xx][yy][(dd+)%][co]){
counts[xx][yy][(dd+)%][co]=step+;
Node tmp;
tmp.x=xx;
tmp.y=yy;
tmp.dir=(dd+)%;
tmp.step=step+;
tmp.color=co;
Q.push(tmp);
}
if(step+<counts[xx][yy][(dd+)%][co]){
counts[xx][yy][(dd+)%][co]=step+;
Node tmp;
tmp.x=xx;
tmp.y=yy;
tmp.dir=(dd+)%;
tmp.step=step+;
tmp.color=co;
Q.push(tmp);
}
int xxx=xx+dir[dd][];
int yyy=yy+dir[dd][];
if(xxx>=&&xxx<=n&&yyy>=&&yyy<=m){
if(map[xxx][yyy]!='#'){
if(step+<counts[xxx][yyy][dd][(co+)%]){
counts[xxx][yyy][dd][(co+)%]=step+;
Node tmp;
tmp.x=xxx;
tmp.y=yyy;
tmp.step=step+;
tmp.color=(co+)%;
tmp.dir=dd;
Q.push(tmp);
} } }
}
} int main(){
int tt=;
while(~scanf("%d%d",&n,&m)&&n>){
if(tt!=)printf("\n");
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
cin>>map[i][j];
if(map[i][j]=='S'){
sx=i;
sy=j;
}
if(map[i][j]=='T'){
ex=i;
ey=j;
}
}
BFS(sx,sy,,);
int minn=INF;
printf("Case #%d\n",tt++);
for(int i=;i<=;i++){
minn=min(minn,counts[ex][ey][i][]);
}
if(minn==INF)printf("destination not reachable\n");
else
printf("minimum time = %d sec\n",minn);
} }
Problem A: The Monocycle的更多相关文章
- The Monocycle(BFS)
The Monocycle Time Limit: 3000MS64bit IO Format: %lld & %llu [Submit] [Go Back] [Status] Des ...
- UVA 10047 The Monocycle (状态记录广搜)
Problem A: The Monocycle A monocycle is a cycle that runs on one wheel and the one we will be consi ...
- UVa10047 The Monocycle
UVa10047 The Monocycle 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19491 (以上摘自htt ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
随机推荐
- [struts2学习笔记] 第一节 关于struts2的简单认知
本文地址:http://blog.csdn.net/sushengmiyan/article/details/40298287 官方文档:http://struts.apache.org/releas ...
- zTree实现地市县三级级联报错(一)
zTree实现地市县三级级联 1.详细报错例如以下: java.lang.IllegalStateException: Failed to load ApplicationContext at org ...
- Objective-C--@property,@synthesize关键字介绍
Objective-C–@property,@synthesize关键字介绍 转载:http://www.cnblogs.com/QM80/p/3576282.html /** 注意:由@proper ...
- ios从相册:摄像头中获取视频
ios从相册/摄像头中获取视频 如何从相册中获取视频 使用的是一个和获取照片相同的类UIImagePickerController //相册中获取视频 - (IBAction)clickViedoOF ...
- 走进 Facebook POP 的世界
POP: 一个流行的可扩展的动画引擎iOS,它支持spring和衰变动态动画,使其可用于构建现实,基于物理交互.Objective - C API允许快速集成, 对于所有的动画和过渡他是成熟的. 解释 ...
- 你需要知道的 Android 拍照适配方案
近段时间,家里陪自己度过大学四年的电脑坏了,挑选好的新电脑配件终于在本周全部到货,自己动手完成组装.从AMD到i7的CPU,6G内存到14G内存,打开 AndroidStudio 的速度终于杠杆的上去 ...
- HTML简单介绍及常见元素
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- WPF DataGrid某列使用多绑定后该列排序失效,列上加入 SortMemberPath 设置即可.
WPF DataGrid某列使用多绑定后该列排序失效 2011-07-14 10:59hdongq | 浏览 1031 次 悬赏:20 在wpf的datagrid中某一列使用了多绑定,但是该列排序失 ...
- phpstorm 快捷方式 (备用)
常用快捷键 设置快捷键:File -> Settings -> IDE Settings -> Keymap -> 选择“eclipse” -> 然后“Copy”一份 ...
- eclipse(myEclipse) 配置maven项目
工作中在myeclipse中导入maven工程后,在pom.xml文件目录执行了mvn eclipse:eclipse 后,发现项目中缺少"Maven Dependencies"目 ...