标签:记录 sample memset pac 位置 def set ack content
题目链接:http://acm.zzuli.edu.cn/problem.php?id=2616
3
5 5
#####
#+EE#
#BEE#
#VB+#
#####
RLU
3 10
##########
#VEEEBEE+#
##########
RRRLLLRRRRRRRRRRR
7 7
#######
#EEB+E#
#E###E#
#E#V#E#
#E###E#
#EEEEE#
#######
UDLRUDLRUDLR
Legendary Legendary Loser
模拟就行了
#include<set> #include<map> #include<stack> #include<queue> #include<cmath> #include<cstdio> #include<cctype> #include<string> #include<vector> #include<climits> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define mst(a) memset(a, 0, sizeof(a)) #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n") using namespace std; typedef long long ll; typedef pair<int, int> P; const double eps = 1e-7; const int INF = 0x3f3f3f3f; const ll ll_INF = 233333333333333; const int maxn = 1e3+10; char _map[maxn][maxn]; struct pp{ int a, b; }point, Case[maxn]; int m, n, kase; void input() { kase = 0; scanf("%d%d", &n, &m); getchar(); for(int i=0;i<n;i++) scanf("%s",_map[i]); for (int i = 0; i<n; ++i) for (int j = 0; j<m; ++j) { if (_map[i][j] == ‘V‘) point.a = i, point.b = j; else if (_map[i][j] == ‘+‘) {//存入终点信息 并把+改成E简化判断 Case[kase].a = i, Case[kase].b = j; ++kase; _map[i][j] = ‘E‘; } } } void checker() { //检查读入数据处理情况 _test; for (int i = 0; i<n; ++i) for (int j = 0; j<m; ++j) printf(j == m-1 ? "%c\n" : "%c", _map[i][j]); } void checker2(){ //检查终点信息存入情况 _test; for (int i = 0; i<kase; ++i) printf("%d %d\n", Case[i].a, Case[i].b); } void move() { char od[maxn]; scanf("%s%*c", od); int len = strlen(od); for (int i = 0; i<len; ++i) { if (od[i] == ‘U‘ && point.a-1 > 0 && _map[point.a-1][point.b] != ‘#‘) { //先判断移动的位置会不会越界 if (_map[point.a-1][point.b] == ‘E‘) { //判断上方是否为空地 swap(_map[point.a-1][point.b], _map[point.a][point.b]); --point.a; } else if (_map[point.a-1][point.b] == ‘B‘ && point.a-2 > 0 && _map[point.a-2][point.b] == ‘E‘) { //判断上方是否为箱子&&箱子能不能移动 swap(_map[point.a-2][point.b], _map[point.a-1][point.b]); swap(_map[point.a-1][point.b], _map[point.a][point.b]); --point.a; } } else if (od[i] == ‘D‘ && point.a+1 < n-1 && _map[point.a+1][point.b] != ‘#‘) { //同上 if (_map[point.a+1][point.b] == ‘E‘) { swap(_map[point.a+1][point.b], _map[point.a][point.b]); ++point.a; } else if (_map[point.a+1][point.b] == ‘B‘ && point.a+2 < n-1 && _map[point.a+2][point.b] == ‘E‘) { //下方 swap(_map[point.a+2][point.b], _map[point.a+1][point.b]); swap(_map[point.a+1][point.b], _map[point.a][point.b]); ++point.a; } } else if (od[i] == ‘L‘ && point.b-1 > 0 && _map[point.a][point.b-1] != ‘#‘) { //同上 if (_map[point.a][point.b-1] == ‘E‘) { swap(_map[point.a][point.b-1], _map[point.a][point.b]); --point.b; } else if (_map[point.a][point.b-1] == ‘B‘ && point.b-2 > 0 && _map[point.a][point.b-2] == ‘E‘) { //左边 swap(_map[point.a][point.b-2], _map[point.a][point.b-1]); swap(_map[point.a][point.b-1], _map[point.a][point.b]); --point.b; } } else if (od[i] == ‘R‘ && point.b+1 < m-1 && _map[point.a][point.b+1] != ‘#‘) { //同上 if (_map[point.a][point.b+1] == ‘E‘) { swap(_map[point.a][point.b+1], _map[point.a][point.b]); ++point.b; } else if (_map[point.a][point.b+1] == ‘B‘ && point.b+2 < m-1 && _map[point.a][point.b+2] == ‘E‘) { //右边 swap(_map[point.a][point.b+2], _map[point.a][point.b+1]); swap(_map[point.a][point.b+1], _map[point.a][point.b]); ++point.b; } } //checker(); 调试 //checker2(); 同上 } } bool ok() { for(int i = 0; i<kase; ++i) if (_map[Case[i].a][Case[i].b] != ‘B‘) //检查每个终点 return false; return true; } int main(void) { int t; scanf("%d%*c", &t); while(t--) { input(); move(); printf(ok() ? "Legendary\n" : "Loser\n"); } return 0; }
标签:记录 sample memset pac 位置 def set ack content
原文地址:https://www.cnblogs.com/shuitiangong/p/12095687.html