uva10047:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=988

题意:题目意思比较绕,就是给出图,从起点'S'出发,到终点'T',有这样的车轮:车轮每转90度,时间加1,上面的均匀5个扇形,从起点开始,是blue色扇形着地,方向向‘上’,然后求出从起点到终点的最后终点是blue扇形着地的最小时间。

题解:用BFS,counts【x】【y】【dir】【co】表示到达x,y时候方向为dir,颜色是co的最小步数,然后就可以BFS。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<queue>
  6. #define INF 1000000000
  7. using namespace std;
  8. const int N=;
  9. struct Node{
  10. int x;
  11. int y;
  12. int step;
  13. int dir;
  14. int color;
  15. };
  16. int n,m;
  17. char map[N][N];
  18. int counts[N][N][N][N];
  19. int sx,sy;
  20. int ex,ey;
  21. void BFS(int x,int y,int d,int color){//0是北1是西2是南3是东 0是绿色,1是白2蓝3红4黑
  22. queue<Node>Q;
  23. Node temp;
  24. temp.x=x;
  25. temp.y=y;
  26. temp.dir=d;
  27. temp.color=color;
  28. temp.step=;
  29. for(int i=;i<=;i++)
  30. for(int j=;j<=;j++)
  31. for(int k=;k<=;k++)
  32. for(int g=;g<=;g++)
  33. counts[i][j][k][g]=INF;
  34. Q.push(temp);
  35. counts[x][y][d][color]=;
  36. int dir[][]={{-,},{,-},{,},{,}};
  37. while(!Q.empty()){
  38. Node tt=Q.front();
  39. Q.pop();
  40. int xx=tt.x;
  41. int yy=tt.y;
  42. int step=tt.step;
  43. int dd=tt.dir;
  44. int co=tt.color;
  45. if(step+<counts[xx][yy][(dd+)%][co]){
  46. counts[xx][yy][(dd+)%][co]=step+;
  47. Node tmp;
  48. tmp.x=xx;
  49. tmp.y=yy;
  50. tmp.dir=(dd+)%;
  51. tmp.step=step+;
  52. tmp.color=co;
  53. Q.push(tmp);
  54. }
  55. if(step+<counts[xx][yy][(dd+)%][co]){
  56. counts[xx][yy][(dd+)%][co]=step+;
  57. Node tmp;
  58. tmp.x=xx;
  59. tmp.y=yy;
  60. tmp.dir=(dd+)%;
  61. tmp.step=step+;
  62. tmp.color=co;
  63. Q.push(tmp);
  64. }
  65. int xxx=xx+dir[dd][];
  66. int yyy=yy+dir[dd][];
  67. if(xxx>=&&xxx<=n&&yyy>=&&yyy<=m){
  68. if(map[xxx][yyy]!='#'){
  69. if(step+<counts[xxx][yyy][dd][(co+)%]){
  70. counts[xxx][yyy][dd][(co+)%]=step+;
  71. Node tmp;
  72. tmp.x=xxx;
  73. tmp.y=yyy;
  74. tmp.step=step+;
  75. tmp.color=(co+)%;
  76. tmp.dir=dd;
  77. Q.push(tmp);
  78. }
  79.  
  80. }
  81.  
  82. }
  83. }
  84. }
  85.  
  86. int main(){
  87. int tt=;
  88. while(~scanf("%d%d",&n,&m)&&n>){
  89. if(tt!=)printf("\n");
  90. for(int i=;i<=n;i++)
  91. for(int j=;j<=m;j++){
  92. cin>>map[i][j];
  93. if(map[i][j]=='S'){
  94. sx=i;
  95. sy=j;
  96. }
  97. if(map[i][j]=='T'){
  98. ex=i;
  99. ey=j;
  100. }
  101. }
  102. BFS(sx,sy,,);
  103. int minn=INF;
  104. printf("Case #%d\n",tt++);
  105. for(int i=;i<=;i++){
  106. minn=min(minn,counts[ex][ey][i][]);
  107. }
  108. if(minn==INF)printf("destination not reachable\n");
  109. else
  110. printf("minimum time = %d sec\n",minn);
  111. }
  112.  
  113. }

Problem A: The Monocycle的更多相关文章

  1. The Monocycle(BFS)

    The Monocycle Time Limit: 3000MS64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Des ...

  2. 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 ...

  3. UVa10047 The Monocycle

    UVa10047 The Monocycle 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19491 (以上摘自htt ...

  4. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  5. 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 ...

  6. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  7. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  8. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  9. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

随机推荐

  1. POJ 3094 Quicksum(简单的问题)

    [简要题意]:题意是非常easy. 看样能理解 [分析]:略. 读取字符串. // 200K 0Ms #include<iostream> using namespace std; int ...

  2. python装饰实现线程同步

    import threading def tryfinally(finallyf):   u"returns a decorator that adds try/finally behavi ...

  3. Spring AOP + AspectJ Annotation Example---reference

    In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...

  4. AndroidStudyDemo之Android4.x介绍

    Android4.x 思维导图 作者:李旺成 时间:2016年4月7日 AndroidStudyDemo 系列篇章开始了!!! AndroidStudyDemo 你值得拥有AndroidStudyDe ...

  5. Hex编码 十六进制编码

    import java.io.UnsupportedEncodingException; import java.net.URLEncoder; /**  * HEX字符串与字节码(字符串)转换工具 ...

  6. Oracle 卸载 不干净

    关闭oracle相关的服务 注册表删除(可能因为oracle及windows的版本不同注册表信息也有些差异): 开始è输入regedit 打开注册表编辑器删除下面的目录 HKEY_LOCAL_MACH ...

  7. @PostConstruct与@PreDestroy

    从Java EE 5规范开始,Servlet中增加了两个影响Servlet生命周期的注解(Annotion):@PostConstruct和@PreDestroy.这两个注解被用来修饰一个非静态的vo ...

  8. Oracle-在线重定义操作文档

    Oracle-在线重定义操作文档 2015年10月8日 15:51 在线重定义的大致操作流程如下: (1)创建基础表A,如果存在,就不需要操作. (2)创建临时的分区表B. (3)开始重定义,将基表A ...

  9. iOS 小知识 - #if , #ifdef , #ifndef.

    Q : 在项目的 .h 文件中, #ifndef XXX_h #define XXX_h //程序段1 #endif  /* XXX_h */ 的作用? A : 如果 XXX.h 不存在,就引入 XX ...

  10. 如何在xcode下面同时安装cocos2d-iphone 和 cocos2d-x模板,其实是因为很喜欢C++的缘故,当时学习的是前者,现在自己摸着石头过河了就(cocos2d-x安装失败 出错)

    首先在Xcode下面配置两个模板的开发环境,其实一个开源库,一个C++移植,学习需要也是,我的mac上一直用的是cocos2d-iphone, 今天想试下cocos2d-x,安装的时间发现安装成功(我 ...