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):前 ...
随机推荐
- LINUX 中的 TCP/IP协议 参数详解
Ipsysctl tutorial 1.0.4 Prev Chapter 3. IPv4 variable reference Next https://www.frozentux.net/ipsys ...
- 你的网站为什么会慢?——用YSlow为你的网站提速
在前面的文章我翻译的文章中分别从内容.服务器.JavaScript和CSS.图片.Coockies和移动应用等几个方面总结了34条提高网站性能的黄金守则,但是这些守则中,有一些是不常用到的,若非有实力 ...
- 关于XML(一)。
关于XML 什么是XML? XML是可扩展标记语言.类似于HTML,XML的宗旨是旨在传输数据,而非显示数据.其标签没有预定义,您需要自行定义标签.XML具有自我描述性,是W3C的推荐标准. XML与 ...
- 分享:带波形的语音播放工具(wavesurfer-js)
项目名称:wavesurfer-js github地址:https://github.com/katspaugh/wavesurfer.js 官网地址:http://wavesurfer-js.org ...
- 【原】ios tableViewCell 自适应高度
原文:http://www.cnblogs.com/A--G/p/4819051.html 前言:之前在做一个类似微博的小需求时候,用table view实现了微博文字和图片等等的基本展示,由于文字和 ...
- CoreBluetooth
Core Bluetooth的基本常识 每个蓝牙4.0设备都是通过服务(Service)和特征(Characteristic)来展示自己的 一个设备必然包含一个或多个服务,每个服务下面又包含若干个特征 ...
- ubuntu系统安装的MySql数据库,远程不能访问的几种可能问题
安装MySQL数据库后一般会遇到远程计算机不能连接的问题,具体问题需要我们排查.可能一:MySql数据库是否提供了外部访问的用户以及权限?可能二:MySql的配置文件是否只绑定了本机ip(ubuntu ...
- 谈一下关于C++函数包装问题
在C++中,我们经常遇到在某个特定的时刻,需要将函数进行包装调用,尤其是当我们需要将不同签名的函数放到同一个集合时,由于函数签名不一致导致我们不能直接将各式各样的函数指针放到诸如list这样的集合中, ...
- 明解C语言,练习13-3,从文件中读入个人信息,按身高排序后显示
#include <stdio.h> #define NUMBER 6 #define F_PATH "D:\\C_C++\\ec13-3\\hw.dat" typed ...
- Qt经典出错信息之”Basic XLib functionality test failed!”
解决方法: 此完整出错信息是在./configure阶段Basic XLib functionality test failed!You might need to modify the includ ...