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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Statues(三维bfs)

發(fā)布時(shí)間:2023/12/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Statues(三维bfs) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8?×?8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria.

Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna’s square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.

At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.

Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.

Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is “.”. If a cell has Maria, then it is represented by character “M”. If a cell has Anna, it is represented by the character “A”. If a cell has a statue, then the cell is represented by character “S”.

It is guaranteed that the last character of the first row is always “A”, the first character of the last line is always “M”. The remaining characters are “.” or “S”.

Output
If Maria wins, print string “WIN”. If the statues win, print string “LOSE”.

Examples
Input
…A






M…
Output
WIN
Input
…A





SS…
M…
Output
LOSE
Input
…A




.S…
S…
MS…
Output
LOSE
題意:要從M走到A,不能走S。而且,M和所有的S交替走,M先走,S后走。M可以留在原地,也可以往八個(gè)方向走。S只能往下走。問能否走到A。
思路:反正就是8*8的一個(gè)圖。直接暴力bfs就可以,記錄一下走了多少步到達(dá)的這個(gè)點(diǎn)。以后再出現(xiàn)就不用重復(fù)這個(gè)情況了。而且在S是逐步下降的,還要注意走到這個(gè)點(diǎn)的時(shí)候有沒有S降到這個(gè)點(diǎn),或者這個(gè)點(diǎn)上一點(diǎn)就是S,都不行。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=10; char s[maxx][maxx]; int mp[maxx][maxx][maxx]; int d[][2]={{0,0},{1,0},{1,1},{-1,0},{0,-1},{1,-1},{-1,1},{-1,-1},{0,1}}; struct node{int x,y,z;node(int a,int b,int c){x=a,y=b,z=c;} }; int sx,sy,ex,ey;inline void bfs(int x,int y,int &flag) {queue<node> q;q.push(node(x,y,0));mp[x][y][0]=1;while(q.size()){node a=q.front();q.pop();if(a.x==ex&&a.y==ey){flag=1;return ;}for(int i=0;i<9;i++){int tx=a.x+d[i][0];int ty=a.y+d[i][1];if(tx<0||tx>=8||ty<0||ty>=8) continue;if(s[tx][ty]=='S'&&a.z==0) continue;if((tx>=a.z+1&&s[tx-a.z-1][ty]=='S')||(tx>=a.z&&s[tx-a.z][ty]=='S')) continue;//這里注意,如果走到這一步的時(shí)候就是S,或者這一點(diǎn)上面就是S,就不能走了。if(mp[tx][ty][a.z+1]) continue;mp[tx][ty][a.z+1]=1;q.push(node(tx,ty,a.z+1));}}return ; } int main() {for(int i=0;i<8;i++) scanf("%s",s[i]);for(int i=0;i<8;i++)for(int j=0;j<8;j++){if(s[i][j]=='M') sx=i,sy=j;if(s[i][j]=='A') ex=i,ey=j;}int flag=0;bfs(sx,sy,flag);if(flag) puts("WIN");else puts("LOSE");return 0; }

努力加油a啊,(o)/~

總結(jié)

以上是生活随笔為你收集整理的Statues(三维bfs)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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