SDUT3184 Fun House (analog)

Source: Internet
Author: User

Fun House Time limit:1000ms Memory limit:65536k Title Description

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

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

xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxx&xxxxInputEach of the preceded is to be integers, W and L, where 5≤w≤20 Is the width of the including the border walls and 5≤l≤20 Is the length of the including the border walls. Following the specification of W and L are L additional lines containing the "the" and "the" and "W" diagram ERs from the alphabet: { * , x , . , / , \\ } . The perimeter is always being comprised of walls, except for one asterisk ( * ) which marks the entrance; the exit is not (yet) marked. A line with zeros indicates the end of input data. OutputFor each test case, the first line would contain the word, house, followed by a space and then an integer that IdentiFi Es the given fun house sequentially. Following that should is a class diagram which includes the proper placement of the exit door, as marked by an ampersand ( & ).  Sample input
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
Tips In both Java and C + + the backslash character ( \\ ) have 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.SOURCE ACM mid-central reginal programming Contest (MCPC2014) sample program

#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 longusing 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 (analog)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.