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

SDUT3184 Fun House(模拟)

时间:2015-04-13 11:02:32      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

Fun House

Time Limit: 1000MS Memory limit: 65536K

题目描述

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 backwardslash 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

输入

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. 

输出

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 (&). 

示例输入

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

示例输出

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

提示

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. 

来源

2014 ACM MId-Central Reginal Programming Contest(MCPC2014)  

示例程序

 


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<map>
#define inf 0x3f3f3f3f
#define LL long long

using namespace std;

struct node
{
    int x;
    int y;
};

char mm[31][31];
int n,m;

void BFS(int ii,int jj,int jx,int jy)
{
    queue<node>q;
    while(!q.empty())
    {
        q.pop();
    }
    struct node t,f;
    t.x = ii;
    t.y = jj;
    q.push(t);
    while(!q.empty())
    {
        t = q.front();
        q.pop();
        f.x = t.x + jx;
        f.y = t.y + jy;
        if(mm[f.x][f.y] == 'x')
        {
            mm[f.x][f.y] = '&';
            break;
        }
        else if(mm[f.x][f.y] == '/')
        {
            if(jx == 0 && jy == 1)
            {
                jx = -1;
                jy = 0;
            }
            else if(jx == 0 && jy == -1)
            {
                jx = 1;
                jy = 0;
            }
            else if(jx == 1 && jy == 0)
            {
                jx = 0;
                jy = -1;
            }
            else if(jx == -1 && jy == 0)
            {
                jx = 0;
                jy = 1;
            }
        }
        else if(mm[f.x][f.y] == '\\')
        {
            if(jx == 0 && jy == 1)
            {
                jx = 1;
                jy = 0;
            }
            else if(jx == 0 && jy == -1)
            {
                jx = -1;
                jy = 0;
            }
            else if(jx == 1 && jy == 0)
            {
                jx = 0;
                jy = 1;
            }
            else if(jx == -1 && jy == 0)
            {
                jx = 0;
                jy = -1;
            }
        }
        q.push(f);
    }

}

int main()
{
    int kk = 0;
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        if(n == 0 && m == 0)
        {
            break;
        }
        int xx,yy;
        for(int i=0; i<n; i++)
        {
            scanf("%s",mm[i]);
            for(int j=0; j<m; j++)
            {
                if(mm[i][j] == '*')
                {
                    xx = i;
                    yy = j;
                    break;
                }
            }
        }
        if(xx == 0)
        {
            BFS(xx,yy,1,0);
        }
        else if(xx == n-1)
        {
            BFS(xx,yy,-1,0);
        }
        else if(yy == 0)
        {
            BFS(xx,yy,0,1);
        }
        else if(yy == m-1)
        {
            BFS(xx,yy,0,-1);
        }
        printf("HOUSE %d\n",++kk);
        for(int i=0; i<n; i++)
        {
            printf("%s\n",mm[i]);
        }
    }
    return 0;
}




SDUT3184 Fun House(模拟)

标签:

原文地址:http://blog.csdn.net/yeguxin/article/details/45021759

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