HUST 1343 C - Coil Judge (哈理工 亚洲区选拔赛前练习赛)
来源:互联网 发布:centos iscsi target 编辑:程序博客网 时间:2024/05/22 07:55
C - Coil Judge
Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %lluDescription
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 Down Left Right) to let the snake go along it until it is blocked by original obstacles or its own body or the border of the maze. The grid which the snake has ever passed would never allow passing any more. 3. If all the grids is occupied by original obstacles or the snake’s body, you win, otherwise repeat procedure 2 and move on until you win or you haven’t choice to move, i.e. you lose. Your mission is simple——given a maze and a solution, you are 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 doesn’t visit all the free grids or the starting point is valid.
Input
The input contains multiple cases ended with EOF. For each case, first line contains two 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 two integers: Y, X, i.e. the snake begins at grid (Y, X) The next line contains a string contains only characters in {U, D, L, R}, meaning “up down left right” in order. Is has at most 1000 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 are 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 grid(s)Case #4: invalid move at (1,2)HINTIf 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 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*/
1 0
- HUST 1343 C - Coil Judge (哈理工 亚洲区选拔赛前练习赛)
- HUST 1347 Reverse Number(哈理工 亚洲区选拔赛前练习赛)
- HUST 1341 A - A Simple Task(哈理工 亚洲区选拔赛练习赛)
- 亚洲赛前训练计划
- 2017ACMICPC亚洲区青岛站:I:The Squared Mosquito Coil【模拟题】
- 哈理工练习赛 HDU 5124 lines
- 哈理工校园编程练习赛杭电 acm 4451 C . Dressing
- 哈理工OJ 2214 Judge(简单的数学题)
- 哈理工练习赛 UVALive 5089 B - Assignments(水题)
- 哈理工acm练习赛 K - Tangled in Cables
- 哈理工校赛1C题
- 省赛前的练习A
- [0] HUST ACM-ICPC Online Judge
- hust OJ如何写一个special judge
- 16哈理工新生赛 C 方方正正 (证明题)
- 杭电 HDU ACM Transportation (哈理工练习赛 费用流拆边)
- 哈理工练习赛 UVALive 5093 F - Seaside(最短路)
- 哈理工练习赛 杭电 HDU Prime Path 1973 poj 3126 Prime Path
- 资料管理器,Treeview,递归
- Compare Version Numbers
- 全面说说反射机制
- C++基础之类
- 测试艰辛与欢乐
- HUST 1343 C - Coil Judge (哈理工 亚洲区选拔赛前练习赛)
- windows下将语料库中所有双声道的wav文件转成单通道
- TCP协议
- java 一道练习题
- 数据库优化方案
- hihoCoder挑战赛14 题目1 : 不等式 枚举?
- 安卓四大组件学习总结
- java8-30
- 来到济宁-惠普实训的体会