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. codechef Turbo Sort 题解

    Input t – the number of numbers in list, then t lines follow [t <= 10^6].  Each line contains one ...

  2. libcurl 使用的几个注意事项

    注:libcurl 入门指南( the tutorial ): http://curl.haxx.se/libcurl/c/libcurl-tutorial.html 0. 为使用的curl url ...

  3. DELPHI TreeView 文件目录树和 设置节点图标 完整

        DELPHI TreeView 文件目录树和 设置节点图标   下载地址 http://download.csdn.net/detail/teststudio/6448293     需要制作 ...

  4. [AngularJS + Webpack] Uglifying your JavaScript

    Angular requires some careful consideration when uglifying your code because of how angular's depend ...

  5. linux 管道--转

    linux 管道 管道是Linux中很重要的一种通信方式,是把一个程序的输出直接连接到另一个程序的输入,常说的管道多是指无名管道,无名管道只能用于具有亲缘关系的进程之间,这是它与有名管道的最大区别. ...

  6. Java基础知识强化之集合框架笔记29:使用LinkedList实现栈数据结构的集合代码(面试题)

    1. 请用LinkedList模拟栈数据结构的集合,并测试:  题目的意思是:     你自己的定义一个集合类,在这个集合类内部可以使用LinkedList模拟,使用LinkedList功能方法封装成 ...

  7. 【bzoj2938】[Poi2000]病毒

    题目描述 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已经找出了所有的病毒代码段,试问,是否 ...

  8. java.util.Random深入理解

    java.util.Random next方法的原理 比较好的参考文档: http://isky001.iteye.com/blog/1339979 package random.utilrandom ...

  9. Android 5.0以上手机出现找不到so文件

    问题描述 最近做项目出了一个bug项目中用到so文件,在5.0以上的手机上会报一个初始化异常错误,并提示找不到so文件.lib里目录结构类似如下  在Android5以下都没有问题,在5.0以上会报错 ...

  10. Eclipse中点击小猫提示Tomcat settings should be set in Tomcat Preference Page

    1.window->preference->tomcat->tomcat-version选择自己tomcat版本 tomcat home 选择tomcat安装目录,即bin的上一层 ...