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;}
- HDU 4213 模拟
- hdu 4213 Sokoban(模拟)
- 【几何模拟】hdu 3286
- hdu 1020 Encoding(模拟)
- hdu 1303 Doubles(模拟)
- hdu 4020 模拟
- HDU **** 暴力模拟
- HDU 4068 模拟
- HDU 4121 模拟
- 【模拟】HDU 4134
- HDU-1279 模拟
- HDU-1035 模拟
- HDU-1283 简单模拟
- HDU-1263 模拟
- hdu 4140 模拟
- hdu 1034 #模拟
- hdu 4194#模拟
- hdu 4350 Card 模拟
- 自定义自适应内容的Label
- PHP中ob_start函数的使用说明
- vCenter中打开虚拟机报错:在主机当前连接状况下不允许执行该操作
- WAS 8.5在HP-UX Itanium上无法图形化安装启动IIM之解
- 开通CSDN 博客了
- HDU 4213 模拟
- HTTP超详细解析——05【代理】
- 【美丽的英文】我喜欢你是寂静的
- Python 3种启动方法: 交互式、python脚本、图形界面运行python
- php处理提交字符串常见函数
- 利用LoadRunner进行http接口功能自动化测试
- vb vb.net 运算符号集
- 贪婪算法
- tchar ANSI编码 Unicode编码