Oh, my goddess nyoj
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 3
seconds, 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 5 O#### ##### #O#O# 3 4
- 樣例輸出
-
14
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int n,m;
char map[60][60];
int dx,dy;
struct node
{
int x;int y;int step;
node(int a,int b,int c):x(a),y(b),step(c){
}
node(){
}
friend bool operator<(node a,node b)
{
return a.step>b.step;
}
};
int dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
bool vis[60][60];
int bfs()
{
priority_queue<node>q;
q.push(node(1,1,0));
vis[1][1]=true;
while(!q.empty()){
node cur=q.top();
q.pop();
if(cur.x==dx&&cur.y==dy)return cur.step;
for(int i=0;i<4;i++)
{
int xx=cur.x+dir[i][0];
int yy=cur.y+dir[i][1];
if(xx<1||xx>n||yy<1||yy>m||vis[xx][yy])continue;
vis[xx][yy]=true;
if(map[xx][yy]=='#')
{
q.push(node(xx,yy,cur.step+4));
}
if(map[xx][yy]=='O')
{
q.push(node(xx,yy,cur.step+1));
}
}
}
return 0;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>map[i][j];
}
}
scanf("%d%d",&dx,&dy);
memset(vis,false,sizeof(vis));
int res=bfs();
printf("%d\n",res);
printf("\n");
}
return 0;
}
很尷尬哎,O看成了o
相關文章
- oh my zsh 常用外掛
- iTerm2 & Oh My Zsh
- Mac 安裝 oh-my-zshMac
- 【轉】oh-my-zsh: git PluginGitPlugin
- linux安裝oh-my-zshLinux
- Ubuntu下安裝oh-my-zshUbuntu
- Mac 配置 iTerm2 + oh-my-zshMac
- Linux 配置 zsh 以及 oh-my-zshLinux
- oh-my-zsh 主題樣式列表
- Ubuntu系列——炫酷的oh-my-zshUbuntu
- Tmux與Oh-my-zsh環境整合UX
- 安裝oh-my-zsh(命令列工具)命令列
- oh-my-zsh的安裝與基本配置
- mac os安裝iTerm2和oh my zshMac
- 【實用筆記】PowerShell 美化成 oh-my-zsh筆記
- Mac 下 美化 iterm2 使用 oh-my-zshMac
- 樹莓派提高shell逼格oh-my-zsh樹莓派
- Mac終端美化(iterm2+oh-my-zsh+vim)Mac
- Oh My Terminal! 實用與裝X齊飛記
- 在 Oh-My-Zsh 內設定命令列標題命令列
- Macos iTerm2 oh-my-zsh 安裝命令失敗Mac
- oh-my-zsh: bracketed-paste-magic:zle:47: not enough arguments for -URacketAST
- Oh my God, Swagger API文件竟然可以這樣寫?GoSwaggerAPI
- Mac 配置 oh-my-zsh 和命令列自動補全Mac命令列
- Ubuntu 下 Oh My Zsh 的最佳實踐「安裝及配置」Ubuntu
- 在ubuntu中安裝與配置zsh與oh-my-zshUbuntu
- 目前還算滿意的 iTerm2 + oh-my-zsh 配置
- 利器 | Terminal & Shell 改造記錄 Windows Terminal + Oh My ZSH + TmuxWindowsUX
- Mac終端最好的體驗之 iTerm2 + Oh My ZshMac
- 為MAC配置終端環境iTerm2+Zsh+oh-my-zshMac
- zsh 下 git 別名(alias) 和 oh-my-zsh git 外掛的故事Git
- 三句命令給MacBook安裝oh my zsh 走向高逼格shellMac
- 十分鐘定製你的私人Mac Treminal 皮膚:oh-my-zshMacREM
- nyoj 8 一種排序排序
- NYOJ--字首式計算
- Oh-My-Zsh 提示符只顯示當前路徑,不需要修改主題檔案
- NYOJ--重建二叉樹二叉樹
- NYOJ 480 Fibonacci Again!AI