Oh, my goddess 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Shining Knight is the embodiment of justice an
来源:互联网 发布:云南广电网络集团待遇 编辑:程序博客网 时间:2024/05/18 01:54
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
char map[55][55];
int vis[55][55];
int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int n,m;
int ex,ey;
struct dot
{
int x,y;
int step;
friend bool operator<(dot a,dot b)
{
return a.step>b.step;
}
};
int bfs(int x,int y)
{
dot a,b;
priority_queue<dot> all;
a.x=x;
a.y=y;
a.step=0;
all.push(a);
vis[a.x][a.y]=1;
while(!all.empty())
{
a=all.top();
all.pop();
if(a.x==ex&&a.y==ey)
return a.step;
for(int i=0;i<4;i++)
{
b.x=a.x+dir[i][0];
b.y=a.y+dir[i][1];
if(b.x<1||b.x>n||b.y<1||b.y>m||vis[b.x][b.y])
continue;
if(map[b.x][b.y]=='#')
b.step=a.step+4;
if(map[b.x][b.y]=='O')
b.step=a.step+1;
//cout<<"x="<<b.x<<",y="<<b.y<<",step="<<b.step<<endl;
all.push(b);
vis[b.x][b.y]=1;
}
}
return 0;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
{
getchar();
for(int j=1;j<=m;j++)
{
scanf("%c",&map[i][j]);
}
}
scanf("%d%d",&ex,&ey);
printf("%d\n",bfs(1,1));
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
char map[55][55];
int vis[55][55];
int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int n,m;
int ex,ey;
struct dot
{
int x,y;
int step;
friend bool operator<(dot a,dot b)
{
return a.step>b.step;
}
};
int bfs(int x,int y)
{
dot a,b;
priority_queue<dot> all;
a.x=x;
a.y=y;
a.step=0;
all.push(a);
vis[a.x][a.y]=1;
while(!all.empty())
{
a=all.top();
all.pop();
if(a.x==ex&&a.y==ey)
return a.step;
for(int i=0;i<4;i++)
{
b.x=a.x+dir[i][0];
b.y=a.y+dir[i][1];
if(b.x<1||b.x>n||b.y<1||b.y>m||vis[b.x][b.y])
continue;
if(map[b.x][b.y]=='#')
b.step=a.step+4;
if(map[b.x][b.y]=='O')
b.step=a.step+1;
//cout<<"x="<<b.x<<",y="<<b.y<<",step="<<b.step<<endl;
all.push(b);
vis[b.x][b.y]=1;
}
}
return 0;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
{
getchar();
for(int j=1;j<=m;j++)
{
scanf("%c",&map[i][j]);
}
}
scanf("%d%d",&ex,&ey);
printf("%d\n",bfs(1,1));
}
return 0;
}
阅读全文
0 0
- Oh, my goddess 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Shining Knight is the embodiment of justice an
- nyist.acm喷水装置(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3
- 最大长方形(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Largest Rectangle in a Histogram A histogram is a p
- 鸡兔同笼 时间限制:3000 ms | 内存限制:65535 KB 难度:1
- NYISTOJ比大小 时间限制:3000 ms | 内存限制:65535 KB 难度:2
- acmnyist排队打饭 时间限制:3000 ms | 内存限制:65535 KB 难度:2
- acm nyist字符串逆序输出 时间限制:3000 ms | 内存限制:65535 KB 难度:0
- 开方数 时间限制:500 ms | 内存限制:65535 KB 难度:3
- 01串 时间限制:1000 ms | 内存限制:65535 KB 难度:2
- acm nyist完数? 时间限制:1000 ms | 内存限制:65535 KB 难度:1
- Vote 时间限制:1000 ms | 内存限制:65535 KB 难度:1
- 比较字母大小 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 任意给出两个英文字母,比较它们的大小,规定26个英文字母A,B,C.....Z依次从大到小。
- 两点距离 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 输入两点坐标(X1,Y1),(X2,Y2)(0<=x1,x2,y1,y2<=1000),计算并输出两点间的距离。
- 合纵连横 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 乱世天下,诸侯割据。每个诸侯王都有一片自己的领土。但是不是所有的诸侯王都是安分守己的,实力强大的诸侯国会设法吞并
- 九九乘法表 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 小时候学过的九九乘法表也许将会扎根于我们一生的记忆,现在让我们重温那些温暖的记忆,请编程输出九九乘
- A+B Problem(V) 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 做了A+B Problem之后,Yougth感觉太简单了,于是他想让你求出两个数反
- nyoj 36 最长公共子序列 dp问题最长公共子序列 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共
- 无线网络覆盖 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们的乐乐同学对于网络可算得上是情有独钟,他有一个计划,那就是用无线网覆盖郑州大学。 现在学校给了他一个机
- Angular学习笔记(一)
- 用HTML5开发移动APP
- hdu 1074 doing homework
- CF830B:Cards Sorting(思维)
- Spark随机森林算法对数据分类(一)——计算准确率和召回率
- Oh, my goddess 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Shining Knight is the embodiment of justice an
- hadoop2.6.0在eclipse下面调试程序看不到日志的解决方法
- 【GAN】简述生成对抗式网络
- poj2151 数学+概率dp
- mapreduce--倒排索引
- 对决
- cpython编译
- CAP定理
- 木棒问题