码迷,mamicode.com
首页 > 其他好文 > 详细

Sicily 7151. 1758!

时间:2015-03-30 09:16:52      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:sicily

7151. 1758!

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

1758 is coming! Some boys want to find their dancing partners. For convenience, you may assume the square is divided into N*M grids. The bottom left corner is (0, 0), and the top right corner is (N-1, M-1). The grids and directions are displayed below:

 

(0, M-1)

(1, M-1)

……

(N-1,M-1)

……

……

……

……

(0,1)

(1,1)

……

(N-1,1)

(0,0)

(1,0)

……

(N-1,0)

North

When a boy enters the square, he will choose one suitable place as his original position and creates a sequence of moving steps. Some boys may share the same place as their original position, and all of them will wander around according to their own sequence of moving steps.

The boys may have different power values, and can be divided into 3 groups according to their power values.

The first group of boys is very stupid, such as wenyue and Latsyrc, the power values of whom are less than 0. They cannot sense the edge of the square. So sometimes they may step outside the square and no matter what moving steps they receive later, they will never get back to the square. Moreover, they will fall into the river. (You know, the river is across the square in SYSU.)

The second group of boys’ power values are exactly 0, such as superkterry, superlzqxh and superjandy. If they stand on the edge of the square and the next moving step is to go out of the square, they will ignore this step. After that, they will continue to wander around according to the following moving steps.

The third group of boys has super power, such as captainithlony, OYoung, Joe, JFantasy and davidmg. Their power values are greater than 0. If the next moving step makes them get out of the square, they can transfer to the opposite site. For example, if someone now stands on (N-1,M-1), the next 4 moving steps are ‘NESW’, then he will be transferred to 4 grids by the following order (N-1,0) , (0,0), (0, M-1), (N-1M-1).

Now comes your task, all you have to do is just to display the final positions of each boy. If the boy is out of square, you should print as OUTPUT shows.

Enjoy your 1758!

 

Input

The input consists of multiple test cases. The first line of each case contains three integers N, M and K (1 <= N, M, K <= 100), which denote the size of the square (N*M) and the number of people. The next K lines display in the following form S, X, Y, P, L, which give the name of a boy S, the boy’s original position (X, Y), the boy’s power value P (-10000 <= P <= 10000) and the sequence of his moving steps L. You can assume that the lengths of S and L are no more than 20, and each character in L is one of the following: N, S, W, E. Each boy’s original position is inside the square. X, Y and P are all integers. All the boys’ names contain only upper and lower letters, and no two boys share the same name.

The input is terminated with three 0’s. This test case should not be processed.

 

Output

For each test case, you should output all boys’ final status in the same order as they appear in input, one line for each boy. If the boy is still inside the square, you should output his final position. If the boy has fallen into the river, you should print “XXX is out of square!”, here XXX means the poor boy’s name.

After each output test set, your program should print exactly one blank line.

 

Sample Input

10 10 6
ithlony 5 5 9876 NW
wenyue 9 8 -2222 NNNSSS
OYoung 9 9 8765 NES
Joe 4 3 2222 SESESESESEN
JFantasy 6 7 7654 EES
Davidmg 2 5 6543 NWW
10 10 4
Latsyrc 0 9 -2222 N
finalkterry 1 1 0 SS
addoillzqxh 6 6 0 WWWWWWWWWS
addrpjandy 8 7 0 EEEEENEEEEE
0 0 0

Sample Output

4 6
wenyue is out of square!
0 9
9 9
8 6
0 6

Latsyrc is out of square!
1 0
0 5
9 8

Problem Source

“星海通杯”第四届中山大学ICPC新手赛 by 莫思颖

#include <string.h>
#include <vector>
#include <queue>
#include <stdio.h>
#include <stack>
using namespace std;

int n, m;

bool will_be_out(int pos_i, int pos_j, char move) {
    if (pos_i == 0 && move == 'W')
        return true;
    if (pos_i == n - 1 && move == 'E')
        return true;
    if (pos_j == 0 && move == 'S')
        return true;
    if (pos_j == m - 1 && move == 'N')
        return true;
    return false;
}

int main() {
    int k, pos_i, pos_j, p, i, j;
    char name[30], move[30];
    while (scanf("%d%d%d", &n, &m, &k) && n != 0) {
        for (j = 0; j < k; j++) {
            memset(name, '\0', sizeof(name));
            memset(move, '\0', sizeof(move));
            scanf("%s%d%d%d%s", name, &pos_i, &pos_j, &p, move);
            for (i = 0; i < (int)strlen(move); i++) {
                if (will_be_out(pos_i, pos_j, move[i])) {
                    if (p < 0) {
                        printf("%s is out of square!\n", name);
                        break;
                    } else if (p == 0) {
                        continue;
                    } else {
                        if (move[i] == 'E')
                            pos_i = 0;
                        else if (move[i] == 'W')
                            pos_i = n - 1;
                        else if (move[i] == 'S')
                            pos_j = m - 1;
                        else
                            pos_j = 0;
                        continue;
                    }
                } else {
                    if (move[i] == 'E')
                        pos_i++;
                    else if (move[i] == 'W')
                        pos_i--;
                    else if (move[i] == 'S')
                        pos_j--;
                    else
                        pos_j++;
                }
            }
            if (i == (int)strlen(move))
                printf("%d %d\n", pos_i, pos_j);
        }
        printf("\n");
    }
    return 0;
}                                 


Sicily 7151. 1758!

标签:sicily

原文地址:http://blog.csdn.net/u012925008/article/details/44739813

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!