Description
Input
Output
Sample Input
3 5 ..... .X... ...X. 2 4 ULDRUR 3 5 ..... .X... ...X. 1 1 ULDRUR 3 5 ..... .X... ...X. 2 4 ULDR 3 5 ..... .X... ...X. 2 4 ULDRUL
Sample Output
Case #1: correct Case #2: invalid starting point Case #3: 2 more free grid(s) Case #4: invalid move at (1,2) HINT If there are redundant moves after you won, the solution is considered as invalid move like Case #4. 我们队今天挂了15发。。坑在哪儿呢! 在于输入的时候起点可能并不在n * m 范围内!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 吐血了~~~~~~~~~~~/*============================================================================= # # Author: liangshu - cbam # # QQ : 756029571 # # School : 哈尔滨理工大学 # # Last modified: 2015-08-30 22:26 # # Filename: A.cpp # # Description: # The people who are crazy enough to think they can change the world, are the ones who do ! =============================================================================*/ # #include<iostream> #include<sstream> #include<algorithm> #include<cstdio> #include<string.h> #include<cctype> #include<string> #include<cmath> #include<vector> #include<stack> #include<queue> #include<map> #include<set> using namespace std; const int INF = 34; char cnt[INF][INF]; int main() { int n, m; int cs = 1; while(scanf("%d%d",&n, &m) != EOF) { memset(cnt, '\0', sizeof(cnt)); int s1 = 1,s = 0; for(int i = 0; i < n; i++) { scanf("%s",cnt[i]); for(int j = 0; j < m; j++) { if(cnt[i][j] == '.') { s++; } } } int x, y; scanf("%d%d",&x, &y); string str; cin>>str; if(cnt[x][y] == 'X' || (x < 0 )||x >= n || y < 0 || y >= m) { printf("Case #%d: invalid starting point\n",cs++); continue; } cnt[x][y] = '*'; int flag = 0; for(int kk = 0; kk < str.size(); kk++) { if(str[kk] == 'U') { int x1; for(int j = 1; ; j ++) { x1 = x - j; if(x1 < 0) { if(j == 1) { printf("Case #%d: invalid move at (%d,%d)\n",cs++,x1 + 1, y); flag = 1; } break; } else if(cnt[x1][y] == 'X' ) { if(j == 1) { printf("Case #%d: invalid move at (%d,%d)\n",cs++,x1 + 1, y); flag = 1; } break; } else if(cnt[x1][y] == '*') { if(j == 1) { printf("Case #%d: invalid move at (%d,%d)\n",cs++,x1 + 1, y); flag = 1; } break; } else { s1++; cnt[x1][y] = '*'; } } x = x1 + 1; } else if(str[kk] == 'L') { int y1; for(int j = 1; ; j ++) { y1 = y - j; if(y1 < 0 || cnt[x][y1] == 'X' || cnt[x][y1] == '*') { if(j == 1) { printf("Case #%d: invalid move at (%d,%d)\n",cs++,x, y1 + 1); flag = 1; } break; } else { s1++; cnt[x][y1] = '*'; } } y = y1 + 1; } else if(str[kk] == 'D') { int x1; for(int j = 1; ; j ++) { x1 = x + j; if(x1 >= n || cnt[x1][y] == 'X' ||cnt[x1][y] == '*') { if(j == 1) { printf("Case #%d: invalid move at (%d,%d)\n",cs++,x1 - 1, y); flag = 1; } break; } else { cnt[x1][y] = '*'; s1++; } } x = x1 - 1; } else if(str[kk] == 'R') { int y1; for(int j = 1; ; j ++) { y1 = y + j; if(y1 >= m || cnt[x][y1] == 'X' || cnt[x][y1] == '*') { if(j == 1) { printf("Case #%d: invalid move at (%d,%d)\n",cs++,x, y1 - 1); flag = 1; } break; } else { s1++; cnt[x][y1] = '*'; } } y = y1 - 1; } if(flag) break; } if(flag)continue; if(s == s1) { printf("Case #%d: correct\n",cs++); } else printf("Case #%d: %d more free grid(s)\n",cs++,s - s1); } return 0; } /* 3 6 ...... ...... ..X... 2 5 ULDRURD 3 3 X.X X.X X.X 2 1 UU 3 5 ..... .X... ...X. 2 4 ULDRURD 3 5 ..... .X... ...X. 1 1 ULDRUR 3 5 ..... .X... ...X. 2 4 ULDR 3 5 ..... .X.X. ...X. 2 4 ULDRUL */
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/lsgqjh/article/details/48110471