日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #301 (Div. 2) C. Ice Cave BFS

發(fā)布時間:2023/12/19 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #301 (Div. 2) C. Ice Cave BFS 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

C. Ice Cave

Time Limit: 1 Sec??Memory Limit: 256 MB

題目連接

http://codeforces.com/contest/540/problem/C

Description

You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.

The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.

Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r,?c).

You are staying in the cell (r1,?c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2,?c2) since the exit to the next level is there. Can you do this?

Input

The first line contains two integers, n and m (1?≤?n,?m?≤?500)?— the number of rows and columns in the cave description.

Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).

The next line contains two integers, r1 and c1 (1?≤?r1?≤?n,?1?≤?c1?≤?m)?— your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1,?c1), that is, the ice on the starting cell is initially cracked.

The next line contains two integers r2 and c2 (1?≤?r2?≤?n,?1?≤?c2?≤?m)?— the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.

Output

If you can reach the destination, print 'YES', otherwise print 'NO'.

?

?

Sample Input

4 6
X...XX
...XX.
.X..X.
......
1 6
2 2

?

Sample Output

YES

?

HINT

In the first sample test one possible path is:

After the first visit of cell (2,?2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.

題意

有一個矩形區(qū)域,一開始你在一個地方,你只能走.的位置,走了之后.就會變成X,然后你必須讓終點變成x,然后再走上去

問你可不可行

題解:

BFS搞一搞就好了,裸題= =

代碼:

?

//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 200001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //§?§é§à§é¨f§3 const int inf=0x3f3f3f3f; /*inline void P(int x) {Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts(""); } */ inline ll read() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } inline void P(int x) {Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts(""); } //**************************************************************************************string s[1000]; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; struct node {int x,y;int t; }; int vis[1000][1000]; int main() {int n=read(),m=read();for(int i=0;i<n;i++)cin>>s[i];node st,ed;cin>>st.x>>st.y;st.x--,st.y--;st.t=0;cin>>ed.x>>ed.y;ed.x--,ed.y--;queue<node> q;q.push(st);while(!q.empty()){node now=q.front();q.pop();for(int i=0;i<4;i++){node next=now;next.x+=dx[i];next.y+=dy[i];next.t++;if(next.x<0||next.x>=n||next.y<0||next.y>=m)continue;if(next.x==ed.x&&next.y==ed.y&&s[next.x][next.y]=='X'){printf("YES\n");return 0;}if(s[next.x][next.y]=='X')continue;q.push(next);s[next.x][next.y]='X';}}printf("NO\n"); }

?

總結(jié)

以上是生活随笔為你收集整理的Codeforces Round #301 (Div. 2) C. Ice Cave BFS的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。