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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 129C】Statues(思维,bfs)

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 129C】Statues(思维,bfs) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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

題目大意:

給一個8*8的棋盤,左下角的人要走到右上角去(左下角為‘M’,右上角為‘A’),‘S’代表障礙物,每隔一秒障礙物會掉落一層,掉到最低層后的下一秒會掉出棋盤。對于每一秒,‘M’先走,障礙物再掉落。問‘M’能否走到‘A’處?

解題報告:

直接暴力bfs,剪枝如下:當步數>=8時,則一定成立。(如果改成步數>8,則會MLE,,輸出了一下棧的大小是3e7左右,再加上結構體類型,確實會MLE)

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; struct Node {int x,y,s;Node(int x=0,int y=0,int s=0):x(x),y(y),s(s){} }; char s[11][11]; int nx[8] = {0,1,1,1,0,-1,-1,-1}; int ny[8] = {1,1,0,-1,-1,-1,0,1},maxsize; bool bfs(int stx,int sty) {queue<Node> q;q.push(Node(stx,sty,0));while(q.size()) {Node cur = q.front();q.pop();if(s[max(1,cur.x-cur.s-1)][cur.y] != 'S') q.push(Node(cur.x,cur.y,cur.s+1));if(cur.s >= 8) return 1;for(int i = 0; i<8; i++) {int tx = cur.x + nx[i],ty = cur.y + ny[i];if(s[max(1,tx-cur.s-1)][ty] == 'S' || s[max(1,tx-cur.s)][ty] == 'S') continue;if(tx < 1 || tx > 8 || ty < 1 || ty > 8) continue;q.push(Node(tx,ty,cur.s+1));}}return 0; } int main() {for(int i = 1; i<=8; i++) scanf("%s",s[i]+1); if(bfs(8,1) == 1) puts("WIN");else puts("LOSE"); // printf("%d\n",maxsize);return 0 ; }

?

總結

以上是生活随笔為你收集整理的【CodeForces - 129C】Statues(思维,bfs)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。