Fun House

来源:互联网 发布:c语言length函数 编辑:程序博客网 时间:2024/05/16 05:03

Description

American Carnival Makers Inc. (ACM) has a long history of designing rides and attractions. One of their more popular attractions is a fun house that includes a room of mirrors. Their trademark is to set up the room so that when looking forward from the entry door, the exit door appears to be directly ahead. However, the room has double-sided mirrors placed throughout at 45 degree angles. So, the exit door can be on any of the walls of the room. The set designer always places the entry and mirrors, but can never seem to be bothered to place the exit door. One of your jobs as part of the construction crew is to determine the placement of the exit door for the room given an original design.

The final diagram for a sample room is given below. The asterisk (*) marks the entry way, lower case x's mark the walls, the mirrors are given by the forward and backward slash characters (/ and \), open spaces with no visual obstructions are marked by periods (.), and the desired placement of the exit is marked with an ampersand (&). In the input diagram, there is an 'x' in place of the '&', since the exit has not yet been located. You need to alter the input diagram by replacing the proper 'x' with an '&' to identify the exit. Note that entrances and exits can appear on any of the walls (although never a corner), and that it is physically impossible for the exit to be the same as the entrance. (You don't need to understand why this is so, although it may be fun to think about.)

xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxx&xxxx

Input

Each room will be preceded by two integers, W and L, where 5 ≤ W ≤ 20 is the width of the room including the border walls and 5 ≤ L ≤ 20 is the length of the room including the border walls. Following the specification of W and L are L additional lines containing the room diagram, with each line having W characters from the alphabet: { * , x , . , / , \ }. The perimeter will always be comprised of walls, except for one asterisk (*) which marks the entrance; the exit is not (yet) marked. A line with two zeros indicates the end of input data.

Output

For each test case, the first line will contain the word, HOUSE, followed by a space and then an integer that identifies the given fun house sequentially. Following that should be a room diagram which includes the proper placement of the exit door, as marked by an ampersand (&).

Sample Input

11 6xxxxxxxxxxxx../..\...xx..../....x*../......xx.........xxxxxxxxxxxx5 5xxxxx*...xx...xx...xxxxxx5 5xxxxxx./\x*./.xx..\xxxxxx6 6xxx*xxx/...xx....xx/./.xx\./.xxxxxxx10 10xxxxxxxxxxx.../\...xx........xx........xx.../\..\x*...\/../xx........xx........xx...\/...xxxxxxxxxxx0 0

Sample Output

HOUSE 1xxxxxxxxxxxx../..\...xx..../....x*../......xx.........xxxxxxx&xxxxHOUSE 2xxxxx*...&x...xx...xxxxxxHOUSE 3xxxxxx./\x*./.xx..\&xxxxxHOUSE 4xxx*xxx/...xx....xx/./.&x\./.xxxxxxxHOUSE 5xxxxxxxxxxx.../\...xx........xx........x&.../\..\x*...\/../xx........xx........xx...\/...xxxxxxxxxxx


题意:由‘*’处垂直射入一条光线,若遇到'/'或'\',则光线成90°反射。当遇到边界时结束,并将'x'改为'&'。然后整个输出。


标程:

# include <cstdio># include <iostream>using namespace std;char str[30][30];//change数组表示方向的改变;int change[2][4] = {3,2,1,0,2,3,0,1};struct Point{    int x,y;    Point(int x = 0,int y = 0)  :x(x),y(y)  { }}s;void dfs(Point s,int flag){    int x = s.x,y = s.y,F = 1;    while(F)    {        if(flag == 0)   x--;        if(flag == 1)   x++;        if(flag == 2)   y--;        if(flag == 3)   y++;        if(str[x][y]=='/')  flag = change[0][flag];        //'\'是转义符,当它单独表示时,要写两个;        if(str[x][y]=='\\') flag = change[1][flag];        if(str[x][y]=='x')        {            str[x][y] = '&';            F = 0;        }    }}int main(){    //freopen("a.txt","r",stdin);    //freopen("b.txt","r",stdin);    int n,m,cnt = 0;    while(~scanf("%d%d\n",&n,&m)&&n&&m)    {        int flag;        for(int i = 0;i < m;i++)        {            scanf("%s",&str[i]);            getchar();            for(int j = 0;j < n;j++)                if(str[i][j] == '*')    s.x=i,s.y=j;        }        if(s.y == 0)    flag = 3;        if(s.x == 0)    flag = 1;        if(s.y == n-1)  flag = 2;        if(s.x == m-1)  flag = 0;        dfs(s,flag);        printf("HOUSE %d\n",++cnt);        for(int i = 0;i < m;i++)    printf("%s\n",str[i]);    }    return 0;}




1 0