Oh, my goddess
来源:互联网 发布:大数据分析用的数据库 编辑:程序博客网 时间:2024/06/05 00:12
Oh, my goddess时间限制:3000 ms | 内存限制:65535 KB难度:3描述Shining Knight is the embodiment of justice and he has a very sharp sword can even cleavewall. Many bad guys are dead on his sword.One day, two evil sorcerer cgangee and Jackchess decided to give him some colorto see. So they kidnapped Shining Knight's beloved girl--Miss Ice! They built a M x Nmaze with magic and shut her up in it.Shining Knight arrives at the maze entrance immediately. He can reach any adjacent emptysquare of four directions -- up, down, left, and right in 1 second. Or cleave one adjacent wall in 3seconds, namely,turn it into empty square. It's the time to save his goddess! Notice: ShiningKnight won't leave the maze before he find Miss Ice.输入The input consists of blocks of lines. There is a blank line between two blocks.The first line of each block contains two positive integers M <= 50 and N <= 50separated by one space. In each of the next M lines there is a string of length N contentsO and #.O represents empty squares. # means a wall.At last, the location of Miss Ice, ( x, y ). 1 <= x <= M, 1 <= y <= N.(Shining Knight always starts at coordinate ( 1, 1 ). Both Shining and Ice's locationguarantee not to be a wall.)输出The least amount of time Shining Knight takes to save hisgoddess in one line.样例输入3 5O##########O#O#3 4样例输出14个人理解:该题使用优先队列处理结果时间运行语言Accepted40324C/C++#include<stdio.h>#include<queue>#include<string.h>using namespace std;void bb();int x,y,ex,ey,m,n;char vc[51][51];int cc[51][51],vx[4]={-1,0,0,1},vy[4]={0,-1,1,0};struct dear{ int x,y,time; friend bool operator < (dear a,dear b)//由小到大排列 { return a.time>b.time; }};int main(){ int i,j; while(~scanf("%d%d",&m,&n)) { for(i=1;i<=m;i++) { getchar();//回收回车键储存空间 for(j=1;j<=n;j++) { scanf("%c",&vc[i][j]); } } scanf("%d%d",&ex,&ey); bb(); } return 0;}void bb(){ int i; memset(cc,0,sizeof(cc)); priority_queue<dear> pq; dear st={1,1,0}; pq.push(st); cc[1][1]=1; while(pq.empty()!=true) { st=pq.top(); pq.pop(); if(st.x==ex&&st.y==ey) { printf("%d\n",st.time); return; } for(i=0;i<4;i++) { int cx,cy; cx=st.x+vx[i]; cy=st.y+vy[i]; if(cx<1||cx>m||cy<1||cy>n) { continue; } if(!cc[cx][cy]) { int ct=st.time+1; if(vc[cx][cy]=='#') ct+=3; dear cp={cx,cy,ct}; cc[cx][cy]=1; pq.push(cp); } } }}
阅读全文
0 0
- Oh, my goddess
- Oh, my goddess
- oh,my goddess
- oh,my goddess-OJ
- NYOJ 635 Oh, my goddess
- Oh, my goddess(bfs)
- 题目635:Oh, my goddess
- 635 Oh, my goddess【优先队列+bfs】
- nyoj--635--Oh, my goddess(dfs)
- Oh, my goddess(优先队列)
- NYOJ-635 Oh, my goddess C语言
- NYOJ 635 Oh, my goddess (简单BFS)
- nyoj 635 Oh, my goddess 【bfs(简单题)】
- NYOJ 635 Oh, my goddess (BFS + 优先队列)
- NYOJ 635-Oh, my goddess【bfs+优先队列】
- NYOJ - 635 - Oh, my goddess(BFS,优先队列)
- nyoj 635 Oh, my goddess 优先队列+BFS
- Oh, my goddess 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Shining Knight is the embodiment of justice an
- E-POJ-3087 Shuffle'm Up
- J
- matlab之cell的清空
- [KMP][字符串Hash] #93 div1 cf 126B Password
- #bzoj1515#盖房子(DP经典)
- Oh, my goddess
- Python运维之路——协程、事件驱动与异步IO
- Java中状态模式和策略模式的区别
- 线段树: CDOJ1598-加帕里公园的friends(区间合并,单点更新)
- 山峰 2016暑假集训结训赛 by JueChen 栈的维护
- [日常训练] 秀姿势
- CodeForces
- Java排序算法之快速排序
- 关于CSS中的样式继承