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):前 ...
随机推荐
- POJ 3094 Quicksum(简单的问题)
[简要题意]:题意是非常easy. 看样能理解 [分析]:略. 读取字符串. // 200K 0Ms #include<iostream> using namespace std; int ...
- python装饰实现线程同步
import threading def tryfinally(finallyf): u"returns a decorator that adds try/finally behavi ...
- Spring AOP + AspectJ Annotation Example---reference
In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...
- AndroidStudyDemo之Android4.x介绍
Android4.x 思维导图 作者:李旺成 时间:2016年4月7日 AndroidStudyDemo 系列篇章开始了!!! AndroidStudyDemo 你值得拥有AndroidStudyDe ...
- Hex编码 十六进制编码
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; /** * HEX字符串与字节码(字符串)转换工具 ...
- Oracle 卸载 不干净
关闭oracle相关的服务 注册表删除(可能因为oracle及windows的版本不同注册表信息也有些差异): 开始è输入regedit 打开注册表编辑器删除下面的目录 HKEY_LOCAL_MACH ...
- @PostConstruct与@PreDestroy
从Java EE 5规范开始,Servlet中增加了两个影响Servlet生命周期的注解(Annotion):@PostConstruct和@PreDestroy.这两个注解被用来修饰一个非静态的vo ...
- Oracle-在线重定义操作文档
Oracle-在线重定义操作文档 2015年10月8日 15:51 在线重定义的大致操作流程如下: (1)创建基础表A,如果存在,就不需要操作. (2)创建临时的分区表B. (3)开始重定义,将基表A ...
- iOS 小知识 - #if , #ifdef , #ifndef.
Q : 在项目的 .h 文件中, #ifndef XXX_h #define XXX_h //程序段1 #endif /* XXX_h */ 的作用? A : 如果 XXX.h 不存在,就引入 XX ...
- 如何在xcode下面同时安装cocos2d-iphone 和 cocos2d-x模板,其实是因为很喜欢C++的缘故,当时学习的是前者,现在自己摸着石头过河了就(cocos2d-x安装失败 出错)
首先在Xcode下面配置两个模板的开发环境,其实一个开源库,一个C++移植,学习需要也是,我的mac上一直用的是cocos2d-iphone, 今天想试下cocos2d-x,安装的时间发现安装成功(我 ...