C-Coil JudgeTime
Limit:MS
Memory Limit:131072KB
64bit IO Format:%lld &A mp %llu SubmitStatusPracticeHUST 1343
Description
Mortal Coil is a very popular game in the past few months. The game has a rectangular maze with obstacles. You guide a virtual snake. The game goes like this:1. Choose a grid as starting point of the snake. (Then the grid is marked blocked) 2. Choose a direction (Above) to let the snake go along it until it's blocked by original obstacles or it s own body or the border of the maze. The grid which the snake have ever passed would never allow passing any more. 3. If all the grids are occupied by original obstacles or the snake ' s body, you win, otherwise repeat procedure 2 and move On until you win or haven ' t choice to move, i.e. you lose. Your mission is Simple--given a maze and a solution, your is asked to judge whether the solution is correct. If the solution is incorrect, please point out whether it tries-to-step into forbidden grid, it finishes all steps but Doe SN ' t visit all the grids or the starting point is valid.
Input
The input contains multiple cases ended with EOF. For each case, first line contains-Integers:r, C. (3<=r, c<=10) The next R lines each contains C characters--' X ' or '. '. ' X ' represents obstacles and '. ' Represents free grids. The next line contains-integers:y, x, i.e. the snake begins at grid (Y, X) The next line contains a string contains O nly characters in {U, D, L, R}, meaning ' up ' to ' right ' in order. Is have at most of the and at least 1 characters. This line and the above line describe the solution.
Output
For each case output, the result in one line. There is 4 kinds of possible outcomes. You can refer to the Sample Output.
Sample Input
3 5......X ... X.2 4uldrur3 5......X ... X.1 1uldrur3 5......X ... X.2 4ULDR3 5......X ... X.2 4ULDRUL
Sample Output
Case #1: Correctcase #2: Invalid starting point case #3:2 more free grids (s) Case #4: Invalid move at () hintif there ar E redundant moves after your won, the solution is considered as invalid move #4.our team hung up 15 rounds today. Where is the pit? The starting point may not be within the n * M range when the input is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Vomiting blood, ~~~~~~~~~~~. /*=============================================================================## Author:liangshu-cbam # # QQ : 756029571 # # School: Harbin Polytechnic University # # last modified:2015-08-30 22:26## filename:a.cpp## Description: # The people who is crazy enough to think they can change the world, is the ones who does! =============================================================================*/# #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 () {in T N, M; int cs = 1; while (scanf ("%d%d", &n, &m)! = EOF) {memset (CNT, ' n ', 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) {p rintf ("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 + free grid (s) \ n", cs++,s-s1); } return 0;} /*3 6..............X ... 2 5uldrurd3 3X. Xx. Xx. X2 1uu3 5......X ... X.2 4uldrurd3 5......X ... X.1 1uldrur3 5......X ... X.2 4ULDR3 5......x.x .... X.2 4uldrul*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HUST 1343 (pre-qualifying practice in Harbin Polytechnic Asia)