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的更多相关文章
随机推荐
- java 十三周总结
- Python pygame库的应用
今天想用pygame库写一个击打外星人飞船的python程序 这个游戏的效果是操纵一个位于屏幕底端的飞船,通过上下左右控制飞船移动方向,按空格发射子弹.游戏中击杀一批飞船后进入下一关卡.每一关卡击打飞 ...
- (一)U-Boot启动过程--详细版的完全分析
博客地址:http://blog.csdn.net/hare_lee/article/details/6916325
- 3.2.2.5 BRE运算符优先级
在数学表达式里,正则表达式的运算符具有某种已定义的优先级,指的是某个运算符(优先级较高)将比其他运算符先被处理. BRE运算符优先级,由高至低 运算符 表示含义 [..] [= ...
- java8 新特性 lambda过滤
1. 定义实体类 package com.atguigu.java8; public class Employee { private int id; private String name; pri ...
- 【02】Node.js 安装配置(OK)
[02] Node.js 安装配置 本章节我们将向大家介绍在window和Linux上安装Node.js的方法. Node.js安装包及源码下载地址为:http://www.nodejs.org/do ...
- NYOJ2 括号配对问题
括号配对问题 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现在,有一行括号序列,请你检查这行括号是否配对. 输入 第一行输入一个数N(0<N<=1 ...
- 学一学书里的django是怎么写views.py的
他山之石,可以攻玉嘛. 好的习惯有时也是学别人来养成的. 外国人的编码习惯,学啊. from django.core.urlresolvers import reverse_lazy from dja ...
- Stockbroker Grapevine POJ 1125 Floyd
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37069 Accepted: ...
- Servlet监听器(Listener)实例
以下内容是翻译自http://www.journaldev.com/1945/servletcontextlistener-servlet-listener-example: 说明:web.xml的加 ...