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。

 #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的更多相关文章

  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. SQL字符串处理函数大全

    select语句中只能使用sql函数对字段进行操作(链接sql server),select 字段1 from 表1 where 字段1.IndexOf("云")=1;这条语句不对 ...

  2. linux 命令c语言代码实现

    自己学习<APUE>时写的linux下一些命令(大概40个左右)实现,仅当学习使用,这些命令包含cat cp echo head ls paste rmdir tail umask who ...

  3. ROS中Mangle解析

    http://blog.csdn.net/bluecy/article/details/8192307

  4. php 两个数组是否相同,并且输出全面的数据,相同的加一个字段标示

    方法一: $date是数组,数组中有字段id,name; $data1是数组,数组中有字段sort_id,name; 所以要通过$date[$i]['id']==$data1[$j]['sort_id ...

  5. inverse 相关设置

    <set name="students" table = "student" inverse="true"> <!-- 指 ...

  6. AS【常用插件】

    安装插件,Settings -->[Plugins]-->搜索-->点击install-->重启AS 禁用插件,右侧面板会显示出已经安装的插件列表,取消勾选即可禁用插件 AS插 ...

  7. ftp不能上传解决办法

    自己的服务器,然后我分好ftp,有一天,有个客户要传东西,发现怎么也传不上,但是可以下载,,,,弄了半天,目录权限也是完全访问,但还是不行,原来是serv-u分配的空间小了啊,所以只能下载不能上传.. ...

  8. Android 4.0及以上版本接收开机广播BOOT_COMPLETED、开机自启动服务

    1.BootCompletedReceiver.Java文件 public class BootCompletedReceiver extends BroadcastReceiver { @Overr ...

  9. Const和ReadOnly

    总结一下const和readonly有这么几条区别: const和readonly的值一旦初始化则都不再可以改写: const只能在声明时初始化:readonly既可以在声明时初始化也可以在构造器中初 ...

  10. while read line无法循环read文件

    while read line 与for循环的区别 例子:要从一个ip列表中获取ip.port,然后ssh ip 到目标机器进行特定的command操作ssh -o StrictHostKeyChec ...