hdu1180奇怪的楼梯……bfs迷阵……wa该16二级,我太渣滓
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int row,line,xx[4]={-1,1,0,0},yy[4]={0,0,-1,1};
char map[100][100];
bool vis[100][100];
struct node
{
int x,y,step;
}st;
void init()
{
int i,j;
bool flag=1;
for(i=0;i<row;i++)
scanf("%s",map[i]);
for(i=0;flag&&i<row;i++)
for(j=0;flag&&j<line;j++)
if(map[i][j]=='S')
{
st.x=i;
st.y=j;
st.step=0;
flag=0;
}
memset(vis,0,sizeof(vis));
vis[st.x][st.y]=1;
}
bool iscan(int x,int y)
{
if(x<0||y<0||x>=row||y>=line||vis[x][y]||map[x][y]=='*')
return 0;
return 1;
}
void bfs()
{
int i;
queue<node>qq;
node t1,t2;
qq.push(st);
while(qq.size())
{
t1=qq.front();
qq.pop();
if(map[t1.x][t1.y]=='T')
{
printf("%d\n",t1.step);
return;
}
for(i=0;i<4;i++)
{
t2=t1;
t2.x+=xx[i];
t2.y+=yy[i];
t2.step++;
if(!iscan(t2.x,t2.y))
continue;
if(map[t2.x][t2.y]=='.'||map[t2.x][t2.y]=='T')
{
vis[t2.x][t2.y]=1;
qq.push(t2);
}
else if((map[t2.x][t2.y]=='|'&&!(t1.step&1))||(map[t2.x][t2.y]=='-'&&(t1.step&1)))
{
if(i>1)
{
t2=t1;
t2.step++;
qq.push(t2);
continue;
}
t2.x+=xx[i];
if(!iscan(t2.x,t2.y))
continue;
vis[t2.x][t2.y]=1;
qq.push(t2);
}
else
{
if(i<2)
{
t2=t1;
t2.step++;
qq.push(t2);
continue;
}
t2.y+=yy[i];
if(!iscan(t2.x,t2.y))
continue;
vis[t2.x][t2.y]=1;
qq.push(t2);
}
}
}
}
int main()
{
while(scanf("%d%d",&row,&line)!=EOF)
{
init();
bfs();
}
}
版权声明:本文博主原创文章。博客,未经同意不得转载。
hdu1180奇怪的楼梯……bfs迷阵……wa该16二级,我太渣滓的更多相关文章
- hdu1180 诡异的楼梯 bfs
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1180/ 题目和不同的bfs有个不同的地方就是存在横着的或者竖着的楼梯,楼梯每过一个时刻就改变一次横竖的走向,人可 ...
- HDU1180:诡异的楼梯(bfs+优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1180 Problem Description Hogwarts正式开学以后,Harry发现在Hogwarts里, ...
- hdu - 1180 诡异的楼梯 (bfs+优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1180 注意点就是楼梯是在harry移动完之后才会改变方向,那么只要统计到达这个点时间奇偶性,就可以知道当前楼梯是 ...
- hdu 1180 诡异的楼梯 (bfs)
诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Sub ...
- hdu 1180诡异的楼梯(bfs)
诡异的楼梯 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submis ...
- 洛谷P1135 奇怪的电梯 BFS例题
好,这是一道黄题.几个月前(2017.10.29)的我拿了可怜的20分. 这是当年的蒟蒻代码 #include <cstdio> #include <iostream> #in ...
- HDU1180:诡异的楼梯
传送门 题意 迷宫搜索 分析 这题写起来挺简单的,锻炼搜索基本功,一开始用记忆化搜索TLE了,改用访问标记,0ms过了,用优先队列保证终点最快达到,我会在代码中提供一些强力数据 trick 1.遇到梯 ...
- hdu 1548 楼梯 bfs或最短路 dijkstra
http://acm.hdu.edu.cn/showproblem.php?pid=1548 Online Judge Online Exercise Online Teaching Online C ...
- HDU 1548 A strange lift 奇怪的电梯(BFS,水)
题意: 有一座电梯,其中楼层从1-n,每层都有一个数字k,当处于某一层时,只能往上走k层,或者下走k层.楼主在a层,问是否能到达第b层? 思路: 在起点时只能往上走和往下走两个选择,之后的每层都是这样 ...
随机推荐
- 使用Perl合并文件
使用Perl合并文件 有时需要将整个目录下的小文件合并到一个文件中,以便查阅检索 特性 整个目录完全遍历,自动存入单个文件 顺序遍历文件 待合并的目录 合并后的文件内容 syscfg/test1 sy ...
- The behavior of App killed or restored by Android System or by users
What's the behavior of App killed or restored by Android System or by users? First, user kills the a ...
- 基于phonegap开发app的实践
app开发告一段落.期间遇到不少问题,写篇文章记录一下. 为虾米要用phonegap 开发app,至少要考虑android和ios两个版本号吧,android偶能够应付,ios表示全然木有接触过.于是 ...
- vue-cli3使用vue-svg-loader加载svg
vue-svg-loader Documentation - FAQ webpack loader that lets you use SVG files as Vue components Micr ...
- ArcSDE:C#打开SDE数据库的几种方式总结
转自原文 ArcSDE:C#打开SDE数据库的几种方式总结 1.通过指定连接属性参数打开数据库 /// <param name="server">数据库服务器名< ...
- 机器学习算法笔记1_2:分类和逻辑回归(Classification and Logistic regression)
形式: 採用sigmoid函数: g(z)=11+e−z 其导数为g′(z)=(1−g(z))g(z) 如果: 即: 若有m个样本,则似然函数形式是: 对数形式: 採用梯度上升法求其最大值 求导: 更 ...
- [AHK]自定义默认浏览器
https://blog.csdn.net/liuyukuan/article/details/78844383
- 【32.22%】【codeforces 602B】Approximating a Constant Range
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- js进阶正则表达式5几个小实例(原样匹配的字符在正则中原样输出)(取反^)
js进阶正则表达式5几个小实例(原样匹配的字符在正则中原样输出)(取反^) 一.总结 原样匹配的字符在正则中原样输出:var reg4=/第[1-2][0-9]章/g //10-29 取反^:var ...
- Linux下停Tomcat服务器,出现Connection refused错误解决办法
错误内容如下 : 2010-9-19 16:09:58 org.apache.catalina.startup.Catalina stopServer 严重: Catalina.stop: java. ...