Oh,mygoddess
很早的时候就看了这一道题目 , 当时不会做 , 现在 边听歌边写无压力 ........

题意 : 光辉骑士 一直都在 迷宫的右上角 , 第一行给你迷宫的规格 , 下面是迷宫 "O" 代表空地需要花一个单位时间跨越 , "#" 代表
墙 ,需要三个单位的时间把墙破开 , 也就是 "O"为一个时间 "#"为4个时间 .
下面附上代码 .
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<cctype>
using namespace std;
struct node
{
int x,y,step;
friend bool operator <(node s1,node s2)
{
return s1.step>s2.step;
}
};
char a[][];
int n,m,tx,ty,b[][]={,-,,,-,,,},visited[][];
priority_queue<node>Q;
int BFS(int x,int y)
{
node q={x,y,};
Q.push(q);
while(!Q.empty())
{
node e=Q.top(); // 怎么会把 这里 忘了呢 ?
Q.pop();
for(int i=;i<;i++)
{
q.x=e.x+b[i][],q.y=e.y+b[i][]; //怎么 整天 都 弄错 ?
if(q.x>=&&q.x<m&&q.y>=&&q.y<n&&!visited[q.y][q.x])
{
if(a[q.y][q.x]=='O')
q.step=e.step+;
if(a[q.y][q.x]=='#')
q.step=e.step+;
visited[q.y][q.x]=;
Q.push(q);
if(q.x==tx&&q.y==ty) //注意 安放的位置
{
return q.step;
}
}
}
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
scanf(" %c",&a[i][j]);
}
}
scanf("%d%d",&ty,&tx);
tx--;
ty--;
memset(visited,,sizeof(visited));
visited[][]=;
while(!Q.empty()) // 注意 清空
Q.pop();
int mark=BFS(,);
printf("%d\n",mark);
}
}
Oh,mygoddess的更多相关文章
随机推荐
- Python爬虫常用库安装
建议更换pip源到国内镜像,下载会快很多:https://www.cnblogs.com/believepd/p/10499844.html requests pip3 install request ...
- linux which-查找并显示给定命令的绝对路径
推荐:更多Linux 文件查找和比较 命令关注:linux命令大全 which命令用于查找并显示给定命令的绝对路径,环境变量PATH中保存了查找命令时需要遍历的目录.which指令会在环境变量$PAT ...
- 初学hash
hash定义: Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种 ...
- [luoguP1922] 女仆咖啡厅桌游吧(奇奇怪怪的树形DP)
传送门 什么鬼的题? 代码 #include <cstdio> #include <cstring> #include <iostream> #define N 1 ...
- hdu 1853 KM算法
#include<stdio.h> #include<math.h> #include<string.h> #define N 200 #define inf 99 ...
- nginx,tornado,websocket,supervisord配置成型
因为要上生产环境,所以配置还是专业一些比较好. nginx.conf upstream websocket_host { server 127.0.0.1:9527; } location /ws_l ...
- 数据切分——Atlas介绍
Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本号的基础上,改动了大量bu ...
- struts2 与spring整合
要把struts2的action交给spring管理,这样spring才干帮struts2注入须要的的bean(一開始action是由struts初始化,所以想注入spring里面的bean是注入不了 ...
- Fedora下搭建LAMP开发环境
LAMP是Linux + Apache + MySQL +PHP/Python的缩写,是一组常用来搭建动态网站服务器的开源软件.它们本身都是各自独立的程序,但是因为开源并且常放在一起使用,所以拥有了越 ...
- jvm 堆内存 栈内存 大小设置
4种方式配置不同作用域的jvm的堆栈内存. 1.Eclise 中设置jvm内存: 改动eclipse的配置文件,对全部project都起作用 改动eclipse ...