Codeforces Beta Round #94 (Div. 1 Only)A. Statues

---恢复内容开始---

A. Statues
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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
Copy
.......A
........
........
........
........
........
........
M.......
output
Copy
WIN
input
Copy
.......A
........
........
........
........
........
SS......
M.......
output
Copy
LOSE
input
Copy
.......A
........
........
........
........
.S......
S.......
MS......
output
Copy
LOSE




蛮水的一道BFS,我用BFS写的,DFS也可,我比较菜,对着数据改了好几回QAQ




 

char mp[101][101];
int x[65],y[65],top=0;
vector <int> vec[105];
int dx[]={0,0,1,-1,-1,1,1,-1,0},dy[]={1,-1,0,0,-1,1,-1,1,0};
struct inof{
int x,y,Step;
}temp;
queue <inof> P;
int vis[64][64][1000];
bool check(int x,int y, int Step)
{
// if(x==0&&y==2)printf("OOOO((((\n");
if(x<0||y<0||x>=8||y>=8)return false;
if(vis[x][y][Step+1])return false;
int siz = vec[y].size();
for(int i=0;i<siz;i++)
{
int tim = x-vec[y][i];
//if(x==0&&y==2)printf("%d^^^%d\n",tim,Step);
/// printf("1");
if(tim<0)continue;
if(tim==Step+1)return false;
if(tim==Step)return false;
}
return true;
}/*
bool che(int x,int y,int Step)
{
int siz = vec[y].size();
for(int i=0;i<siz;i++)
{
int tim = x-vec[y][i];
if(tim==Step+1)return false;
}
return true;
}*/
int main() {
memset(vis,0,sizeof(vis));
for(int i=0;i<8;i++)cin>>mp[i];
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
if(mp[i][j]=='S')vec[j].push_back(i);
}
}
temp.x=7,temp.y=0,temp.Step=0;
P.push(temp);
while(!P.empty()){
temp = P.front();P.pop(); //if(temp.x==0&&temp.y==1)printf("&&&&&&&&&\n");
//if(!(che(temp.x,temp.y,temp.Step)))continue;
if(mp[temp.x][temp.y]=='A')return 0*printf("WIN");

for(int i=0;i<9;i++){
///printf("1");
int x = temp.x+dx[i],y = temp.y+dy[i];

if(check(x,y,temp.Step))
{
//printf("%d %d\n",x,y);
inof tem;tem.x=x,tem.y=y,tem.Step=temp.Step+1;
P.push(tem);
vis[x][y][temp.Step]=1;
}
}
}
puts("LOSE");
return 0;
}

 

转载于:https://www.cnblogs.com/DreamKill/p/9347587.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值