CSU1562 Fun House

6 篇文章 0 订阅

Fun House

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 6
xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxxxxxxx
5 5
xxxxx
*...x
x...x
x...x
xxxxx
5 5
xxxxx
x./\x
*./.x
x..\x
xxxxx
6 6
xxx*xx
x/...x
x....x
x/./.x
x\./.x
xxxxxx
10 10
xxxxxxxxxx
x.../\...x
x........x
x........x
x.../\..\x
*...\/../x
x........x
x........x
x...\/...x
xxxxxxxxxx
0 0

Sample Output

HOUSE 1
xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxx&xxxx
HOUSE 2
xxxxx
*...&
x...x
x...x
xxxxx
HOUSE 3
xxxxx
x./\x
*./.x
x..\&
xxxxx
HOUSE 4
xxx*xx
x/...x
x....x
x/./.&
x\./.x
xxxxxx
HOUSE 5
xxxxxxxxxx
x.../\...x
x........x
x........x
&.../\..\x
*...\/../x
x........x
x........x
x...\/...x
xxxxxxxxxx

Hint

In both Java and C++ the backslash character (\) has special meaning as an escape character within character and string literals. You must use the combination \\ to express a single backslash within a character or string literal within source code.

————————————————————————————

题目的意思是给出一张只有一个入口的图,问光线射进后从哪射出来,/ \是镜子会反射光
思路:直接dfs暴力跑
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define LL long long
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
#define MAXN 100005

int dir[4][2]= {{-1,0},{0,1},{1,0},{0,-1}};
char mp[50][50];
int m,n;
int esp;

void dfs(int si,int sj,int d)
{

    if(esp==1)
        return ;
    int xx=si+dir[d][0];
    int yy=sj+dir[d][1];
    if(mp[xx][yy]=='.')
    {
        dfs(xx,yy,d);
    }
    else if(mp[xx][yy]=='/')
    {
       if(d==0) d=1;
       else if(d==1) d=0;
       else if(d==2) d=3;
       else if(d==3) d=2;
        dfs(xx,yy,d);
    }
    else if(mp[xx][yy]=='\\')
    {
         if(d==0) d=3;
       else if(d==1) d=2;
       else if(d==2) d=1;
       else if(d==3) d=0;
        dfs(xx,yy,d);
    }
    else if(mp[xx][yy]=='x')
    {
        mp[xx][yy]='&';
        esp=1;
        return;
    }
}

int main()
{
    int si,sj,d;
    int q=1;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0)
            break;
        for(int i=0; i<m; i++)
        {
            scanf("%s",mp[i]);
            for(int j=0; j<n; j++)
                if(mp[i][j]=='*')
                    si=i,sj=j;
        }
        esp=0;
        if(si==0)
            d=2;
        else if(si==m-1)
            d=0;
        else if(sj==0)
            d=1;
        else
            d=3;
        dfs(si,sj,d);
        printf("HOUSE %d\n",q++);
        for(int i=0; i<m; i++)
            printf("%s\n",mp[i]);

    }
    return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值