• 1562: 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
    超时超了10多次,把scanf改成cin就AC了。。。因为一个字符一个字符输入,可能最后会有多个空格,这样就错了,所有尽量改成scanf("%s",str);这样也能过的
    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    char str[100][100];
    int tab[100][100][3];
    int main()
    {
        int n,m,i,j,x,y,h=0,a,b;
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            if(n==0 && m==0)
            break;
            getchar();
            h++;
            memset(str,0,sizeof(str));
            memset(tab,0,sizeof(tab));
            for(i=1;i<=m;i++)
            {
                for(j=1;j<=n;j++)
                {
                    cin>>str[j][i];
                    if(str[j][i]=='*')
                    {
                        x=j;
                        y=i;
                    }
                }
                //if(i!=m)
                //getchar();
            }
            if(x==1)
            {
              tab[x][y][0]=1;
              tab[x][y][1]=0;
            }
            else if(y==1)
            {
                tab[x][y][0]=0;
                tab[x][y][1]=1;
            }
            else if(y==m)
            {
                tab[x][y][0]=0;
                tab[x][y][1]=-1;
            }
            else if(x==n)
            {
                tab[x][y][0]=-1;
                tab[x][y][1]=0;
            }
             
            while(1)
            {
                a=tab[x][y][0];
                b=tab[x][y][1];
                x=x+a;
                y=y+b;
                tab[x][y][0]=a;
                tab[x][y][1]=b;
                if(str[x][y]=='x')
                {
                    str[x][y]='&';
                    break;
                }
                if(str[x][y]=='.')
                continue;
                if(str[x][y]=='/')
                {
                    if(tab[x][y][0]==0)
                    {
                        if(tab[x][y][1]==1)
                        {
                            tab[x][y][0]=-1;
                            tab[x][y][1]=0;
                        }
                        else
                        {
                            tab[x][y][0]=1;
                            tab[x][y][1]=0;
                        }
                    }
                    else if(tab[x][y][1]==0)
                    {
                        if(tab[x][y][0]==1)
                        {
                            tab[x][y][0]=0;
                            tab[x][y][1]=-1;
                        }
                        else if(tab[x][y][0]==-1)
                        {
                            tab[x][y][0]=0;
                            tab[x][y][1]=1;
                        }
                    }
                }
                 
                if(str[x][y]=='\')
                {
                    if(tab[x][y][0]==0)
                    {
                        if(tab[x][y][1]==1)
                        {
                            tab[x][y][0]=1;
                            tab[x][y][1]=0;
                        }
                        else if(tab[x][y][1]==-1)
                        {
                            tab[x][y][0]=-1;
                            tab[x][y][1]=0;
                        }
                    }
                    else if(tab[x][y][1]==0)
                    {
                        if(tab[x][y][0]==1)
                        {
                            tab[x][y][0]=0;
                            tab[x][y][1]=1;
                        }
                        else
                        {
                            tab[x][y][0]=0;
                            tab[x][y][1]=-1;
                        }
                    }
                }
                 
            }
            printf("HOUSE %d
    ",h);
            for(i=1;i<=m;i++)
            {
                for(j=1;j<=n;j++)
                printf("%c",str[j][i]);
                printf("
    ");
            }
        }
         
    }
     
    
  • 相关阅读:
    模块化项目
    mysql mybatis-generator plugin 有page实体类的分页
    mysql mybatis-generator plugin 分页
    eclipse中mybatis generator插件的安装与使用,实现自动生成代码
    linux下安装mysql5.7.17及简单配置
    mybatis-mysql操作存储过程
    解决JSP路径问题的方法(jsp文件开头path, basePath作用)
    windows下开启mysql远程访问
    Java中hashCode的作用
    垃圾收集器与内存分配策略 (深入理解JVM二)
  • 原文地址:https://www.cnblogs.com/herumw/p/9464857.html
Copyright © 2020-2023  润新知