HDU 4213 模拟

来源:互联网 发布:edm群发软件 编辑:程序博客网 时间:2024/06/05 00:17

推箱子 

模拟一下就好了 

水题


#include "stdio.h"#include "string.h"#include "math.h"#include "stdlib.h"int n,m;char str[101][101];int judge(){    int i,j;    for (i=0;i<n;i++)        for (j=0;j<m;j++)            if (str[i][j]=='+' || str[i][j]=='b' || str[i][j]=='W') return 0;    return 1;}int main(){    int Case,i,flag,j,x,y;    char op[101];    Case=0;    while (scanf("%d%d",&n,&m)!=EOF)    {        if (n==0 && m==0) break;        Case++;        getchar();        for (i=0;i<n;i++)        {            gets(str[i]);            for (j=0;j<m;j++)                if (str[i][j]=='w' || str[i][j]=='W')                {                    x=i;                    y=j;                }        }        flag=0;        gets(op);        for (i=0;op[i];i++)        {            if (judge()==1)             {                flag=1;                break;            }            if (op[i]=='U')            {                if (str[x-1][y]=='#') continue;                if (str[x-1][y]=='.' )                {                    str[x-1][y]='w';                    if (str[x][y]=='w') str[x][y]='.';                    else str[x][y]='+';                    x--;                    continue;                }                if (str[x-1][y]=='+')                {                    str[x-1][y]='W';                    if (str[x][y]=='w') str[x][y]='.';                    else str[x][y]='+';                    x--;                    continue;                }                if (str[x-1][y]=='b' || str[x-1][y]=='B')                {                    if (str[x-2][y]=='b' || str[x-2][y]=='B' || str[x-2][y]=='#') continue;                    if (str[x-2][y]=='.') str[x-2][y]='b'; else str[x-2][y]='B';                    if (str[x-1][y]=='b') str[x-1][y]='w'; else str[x-1][y]='W';                    if (str[x][y]=='w') str[x][y]='.'; else str[x][y]='+';                    x--;                    continue;                }            }            if (op[i]=='D')            {                if (str[x+1][y]=='#') continue;                if (str[x+1][y]=='.' )                {                    str[x+1][y]='w';                    if (str[x][y]=='w') str[x][y]='.';                    else str[x][y]='+';                    x++;                    continue;                }                if (str[x+1][y]=='+')                {                    str[x+1][y]='W';                    if (str[x][y]=='w') str[x][y]='.';                    else str[x][y]='+';                    x++;                    continue;                }                if (str[x+1][y]=='b' || str[x+1][y]=='B')                {                    if (str[x+2][y]=='b' || str[x+2][y]=='B' || str[x+2][y]=='#') continue;                    if (str[x+2][y]=='.') str[x+2][y]='b'; else str[x+2][y]='B';                    if (str[x+1][y]=='b') str[x+1][y]='w'; else str[x+1][y]='W';                    if (str[x][y]=='w') str[x][y]='.'; else str[x][y]='+';                    x++;                    continue;                }            }            if (op[i]=='L')            {                if (str[x][y-1]=='#') continue;                if (str[x][y-1]=='.' )                {                    str[x][y-1]='w';                    if (str[x][y]=='w') str[x][y]='.';                    else str[x][y]='+';                    y--;                    continue;                }                if (str[x][y-1]=='+')                {                    str[x][y-1]='W';                    if (str[x][y]=='w') str[x][y]='.';                    else str[x][y]='+';                    y--;                    continue;                }                if (str[x][y-1]=='b' || str[x][y-1]=='B')                {                    if (str[x][y-2]=='b' || str[x][y-2]=='B' || str[x][y-2]=='#') continue;                    if (str[x][y-2]=='.') str[x][y-2]='b'; else str[x][y-2]='B';                    if (str[x][y-1]=='b') str[x][y-1]='w'; else str[x][y-1]='W';                    if (str[x][y]=='w') str[x][y]='.'; else str[x][y]='+';                    y--;                    continue;                }            }            if (op[i]=='R')            {                if (str[x][y+1]=='#') continue;                if (str[x][y+1]=='.' )                {                    str[x][y+1]='w';                    if (str[x][y]=='w') str[x][y]='.';                    else str[x][y]='+';                    y++;                    continue;                }                if (str[x][y+1]=='+')                {                    str[x][y+1]='W';                    if (str[x][y]=='w') str[x][y]='.';                    else str[x][y]='+';                    y++;                    continue;                }                if (str[x][y+1]=='b' || str[x][y+1]=='B')                {                    if (str[x][y+2]=='b' || str[x][y+2]=='B' || str[x][y+2]=='#') continue;                    if (str[x][y+2]=='.') str[x][y+2]='b'; else str[x][y+2]='B';                    if (str[x][y+1]=='b') str[x][y+1]='w'; else str[x][y+1]='W';                    if (str[x][y]=='w') str[x][y]='.'; else str[x][y]='+';                    y++;                    continue;                }            }        } // for op        if (judge()==1) flag=1;        printf("Game %d: ",Case);        if (flag==0)            printf("incomplete\n");        else             printf("complete\n");        for (i=0;i<n;i++)            puts(str[i]);    }    return 0;}


原创粉丝点击