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\n",h);
        for(i=1;i<=m;i++)
        {
            for(j=1;j<=n;j++)
            printf("%c",str[j][i]);
            printf("\n");
        }
    }
     
}
 

1562: Fun House的更多相关文章

  1. 模拟 CSU 1562 Fun House

    题目传送门 /* 题意:光线从 '*' 发射,遇到 '/' 或 '\' 进行反射,最后射到墙上,将 'x' 变成 '&' 模拟:仔细读题,搞清楚要做什么,就是i,j的移动,直到撞到墙,模拟一下 ...

  2. POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)

    题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...

  3. HDU 1562 Guess the number

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1562 Problem Description Happy new year to everybody ...

  4. poj 1562 dfs

    http://poj.org/problem?id=1562 #include<iostream> using namespace std; ,m=,sum=; ][]; ][]={-,, ...

  5. BZOJ 1562 变换序列 二分图匹配+字典序

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1562 题目大意: 思路: 逆序匹配,加边匹配的时候保持字典序小的先加入. 具体证明:h ...

  6. [BZOJ 1562] 变换序列

    Link: BZOJ 1562 传送门 Solution: 一道比较考对$Hungry$算法理解的题目 首先可以轻松看出原序列和答案序列的对应关系,从而建出二分图匹配模型 下面的关键在于如何保证字典序 ...

  7. BZOJ 1562 [NOI2009]变换序列:二分图匹配

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1562 题意: 给定n,定义D(x,y) =  min(|x-y|, n-|x-y|),然后 ...

  8. 51nod 1562 玻璃切割

      1562 玻璃切割 http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1562 题目来源: CodeForces 基准时间 ...

  9. 51nod 1562 玻璃切割 (STL map+一点点的思考)

    1562 玻璃切割 题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 现在有一块玻璃,是长方形的(w 毫米× h 毫米),现在要 ...

  10. POJ 1562 Oil Deposits (HDU 1241 ZOJ 1562) DFS

    现在,又可以和她没心没肺的开着玩笑,感觉真好. 思念,是一种后知后觉的痛. 她说,今后做好朋友吧,说这句话的时候都没感觉.. 我想我该恨我自己,肆无忌惮的把她带进我的梦,当成了梦的主角. 梦醒之后总是 ...

随机推荐

  1. js 判断用户是手机端还是电脑端访问

    通过userAgent 判断,网页可以直接使用 navigation对象 node端 可以通过请求头的 ctx.request.header['user-agent'] const browser = ...

  2. Flutter 基础组件:文本、字体样式

    // 文本.字体样式 import 'package:flutter/material.dart'; class TextFontStyle extends StatelessWidget { // ...

  3. Python3爬取小说并保存到文件

    问题 python课上,老师给同学们布置了一个问题,因为这节课上学的是正则表达式,所以要求利用python爬取小说网的任意小说并保存到文件. 我选的网站的URL是'https://www.biquka ...

  4. DHCP最佳实践(三)

    这是Windows DHCP最佳实践和技巧的最终指南. 如果您有任何最佳做法或技巧,请在下面的评论中发布它们. 在本指南(三)中,我将分享以下DHCP最佳实践和技巧. 仅在需要时才使用IP冲突检测 运 ...

  5. 记忆中的像素块褪色了吗?用开源的体素编辑器重新做个 3D 的吧!

    本文适合对图形表现有兴趣的美术或者开发人员 本文作者:HelloGitHub-Joey 早期的的显示设备像素颗粒较大,使得显示内容的颗粒感严重,像是由一堆方块组成的.比较好的例子就是 GBA 上的游戏 ...

  6. MongoDB数据库,一些的筛选过滤查询操作和db.updae()更新数据库记录遇到的坑。

    缘由:使用MongoDB时遇到一些需要查询/更新操作指定某些字段的业务场景 查询和更新指定字段就需要进行简单的筛选和过滤,也能在大数据量时减少查询消耗时间 1. 查询数据库某些指定字段,同时默认返回_ ...

  7. 面试必问:如何实现Redis分布式锁

    摘要:今天我们来聊聊分布式锁这块知识,具体的来看看Redis分布式锁的实现原理. 一.写在前面 现在面试,一般都会聊聊分布式系统这块的东西.通常面试官都会从服务框架(Spring Cloud.Dubb ...

  8. python(paramiko模块的简单使用)

    #通过paramiko模块连接主机运行bash命令 import paramiko hostname = '192.168.88.31' port = 22 username = 'root' pas ...

  9. (14)-Python3之--虚拟环境virtualenv

    1.安装virtualenv pip install virtualenv 如果是在Linux下需要把virtualenv添加到/usr/bin目录下 # find / -name virtualen ...

  10. 时序数据库 Apache-IoTDB 源码解析之元数据索引块(六)

    上一章聊到 TsFile 索引块的详细介绍,以及一个查询所经过的步骤.详情请见: 时序数据库 Apache-IoTDB 源码解析之文件索引块(五) 打一波广告,欢迎大家访问 IoTDB 仓库,求一波 ...