HUST 1343 (哈理工 亚洲区选拔赛前练习赛)

C - Coil Judge

Time Limit:1000MS    Memory Limit:131072KB    64bit IO Format:%lld
& %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 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 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
*/

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-24 01:33:20

HUST 1343 (哈理工 亚洲区选拔赛前练习赛)的相关文章

HUST 1343 Reverse Number(哈理工 亚洲区选拔赛前练习赛)

G - Reverse Number Time Limit:1000MS    Memory Limit:131072KB    64bit IO Format:%lld & %llu SubmitStatusPracticeHUST 1347 Description Given a non-negative integer sequence A with length N, you can exchange two adjacent numbers each time. After K exc

HUST 1341 A - A Simple Task(哈理工 亚洲区选拔赛练习赛)

A - A Simple Task Time Limit:1000MS    Memory Limit:131072KB    64bit IO Format:%lld & %llu SubmitStatusPracticeHUST 1341 Description As is known to all, lots of birds are living in HUST. A bird has s units of food on the first day, and eats k units

wfu省赛前练习赛(一)第一题

TEX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use " and " to delimit quotations, rather than the mund

2014 39th ACM-ICPC 北京赛区 总结

万万没想到,拿金了. 在经历了西安赛区的打铁经历,感觉我们已经很坦然了.怎么说呢,虽说有阴影,但那也是成长的一步.我在西安打铁之后跟队友跟姐姐说过“如果北京是铜或者铁,我就退役”.记得曾经,很多人问我要搞ACM搞到几年级.有不懂ACM有了解ACM有熟悉ACM的人.好像我只对姐姐正面回答过“看看今年打的成绩吧,感觉今年是关键”.因为大二的时候跟PZ,JM一队,那次有个银,不过主要是靠他们,而且那次也有一定的运气成分.如果今年的两次成绩的最好是银尾或以下,大概我就会退役吧.因为那样的话大概就说明我尽

哈理工 oj 2122 旅行(map + 最短路dij算法)

旅行 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 18(6 users) Total Accepted: 3(3 users) Rating: Special Judge: No Description "04.24,和Sakura去东京天空树,世界上最暖和的地方天空树的顶上. " "04.26.和Sakura去明治神宫.有人在那里举办婚礼." "04.25.和Sakura去迪士尼.鬼屋非

哈理工 oj——队列列列列!!!!!

队列列列列!!!!! Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 337(148 users) Total Accepted: 154(142 users) Rating: Special Judge: No Description xuxu完成了栈的实验要求后,他又很是开心,刚要出去liuda, biaobiao突然问道老师让做的队列的那个实验你写完了么,xuxu顿时大呼悲哉....他给忘记了,怎么办..明天就要上交实验报告了

河大赛 赛前抱佛脚

写在赛前:这个比赛是文件存取操作的,不是像OJ和PAT一样提交代码通过测试用例.就这种文件存取的方式而言,有优点也有缺点,优点就是不会出现TLE啊.缺点就是无法提交代码去通过多个测试用例,如果有部分测试用例无法AC,可能出了考场还发现不了,就很难受.好了骚话少说,拿例题练练手,就本菜鸡自己输入用例进行调试而言,没有发现错误. 特别注意1:请在你使用的计算机 D: 盘建立一个以你学号为名的文件夹,将考试提供的“程序设计输入文件”文件夹中的文件都拷贝至该文件夹备用.最后提交时,将你的学号文件夹中的所

2017ZZUACM省赛选拔试题部分题解----谨以纪念我这卡线滚粗的美好经历

写在前面: 其实心里有些小小的不爽又有点小小的舒畅,为啥捏?不爽当然是因为没被选拔上啦,舒畅捏则是因为没被选拔上反而让自己警醒,学长也提点很多很多."沉下去,然后一战成名"学长如是对我说,我很开心.其实这完全算不算是题解,只是我个人的一些小想法而已.而且到现在还有一题不会...让自己长点记性吧. 题目 A :聪明的田鼠 Time Limit: 1 Sec Memory Limit: 128 MB Description 田鼠MIUMIU来到了一片农田,农田可以看成是一个M*N个方格的矩

HUST 1588 辗转数对

1588 - 辗转数对 时间限制:1秒 内存限制:128兆 155 次提交 27 次通过 题目描述 假设当前有一个数对(a, b),我们可以通过一步将这个数对变为一个新数对(a + b, b)或者是(a, a + b).初始的数对为(1, 1),你的任务是找到一个数字k,即通过最少的步数使得这个数对中至少一个数字等于n. 输入 输入包括多组数据,每组数据包括一行,每行有一个整数n. 输出 每组数据输出一行,每行一个整数n. 样例输入 5 3 样例输出 3 2 提示 第一个样例的方法是 (1,1)