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):前 ...
随机推荐
- 移植opencv库到zedboard(制作运行库镜像) 分类: OpenCV ZedBoard ubuntu shell Eye_Detection 2014-11-08 18:48 172人阅读 评论(0) 收藏
主要参考rainysky的博客 http://ledage.eefocus.com/sj229335457/blog/13-06/295352_ad954.html opencv的话只需要将lib这个 ...
- android 14 进度条和拖动条
进度条: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:l ...
- Java语言基础(五)
Java语言基础(五) 一.浮点数 浮点数就是小数,其标准是IEEE 754,用指数和尾数表示 例如30000=3*10000=3*10^4 其中4是指数,3是尾数 Java中,浮点数有float ...
- iOS-UITableCell详情
iOS-UITableCell详情 表示UITableViewCell风格的常量有: UITableViewCellStyleDefault UITableViewCellStyleSubtitle ...
- 3 - SQL Server 2008 之 使用SQL语句删除约束条件
基本语法为: ALTER TABLE 表名 DROP CONSTRAINT 约束名1,约束名2…… 如果删除一个约束,不需要逗号后的约束名,如果删除两个及两个以上的约束,必须以逗号隔开. 使用上一节中 ...
- Oracle修改被占用的临时表结构
这两天在修改临时表的类型时,提示”attempt to create,alter or drop an index on temporary table already in use“的错误,由于临时 ...
- svs 在创建的时候 上传文件夹 bin obj 这些不要提交
svs 在创建的时候 上传文件夹 bin obj 这些不要提交 右键-去除版本控制并增加到忽略列表
- 处理移动端click事件300ms延迟的好方法—FastClick
下载地址:https://github.com/ftlabs/fastclick 1.click事件为什么有延迟? “...mobile browsers will wait approximatel ...
- spring事务管理学习
spring事务管理学习 spring的事务管理和mysql自己的事务之间的区别 参考很好介绍事务异常回滚的文章 MyBatis+Spring 事务管理 spring中的事务回滚例子 这篇文章讲解了@ ...
- eclipse build很慢的时候,有可能是js文件编译验证慢的问题
第一步: 去除eclipse的JS验证: 将windows->preference->Java Script->Validator->Errors/Warnings-> ...