SDUT3184 Fun House(模拟)

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;
}
时间: 2024-07-29 21:42:17

SDUT3184 Fun House(模拟)的相关文章

CentOS系统启动及内核大破坏模拟实验

讲过了centos的启动流程,此时是不是想来点破坏呢?那就尽情的玩耍吧,记得在实验之前拍个快照,万一哪个环节错误恢复不回来了呢,毕竟数据无价,话不多说,开始. 一.删除伪系统根.(ramdisk文件) (1)模拟误操作删除ramdisk文件. ①模拟误删除initramfs-3.10.0-514.el7.x86_64.img文件. ②为当前正在使用的内核重新制作ramdisk文件 格式为:mkinitrd /boot/initramfs-$(uname -r).img $(uname -r) (

NYOJ 2356: 哈希计划【模拟】

题目描述 众所周知,LLM的算法之所以菜,就是因为成天打游戏,最近LLM突然想玩<金庸群侠传X>,结果进去后各种被虐,LLM就开始研究这个游戏的代码,顺便还学会了一点点点点lua语言,然后就开始了伟大的改游戏代码之旅,然后LLM发现自己too young了,这个游戏把所有的文本都进行了哈希,如果自己改了代码或者剧情文本的话它哈希出来的值就会和原来的哈希值不一样......然后游戏就会打不开.....,现在LLM发现了文本的哈希函数,要求你写个程序,功能为: 输入一段字符串,输出一个哈希值 为了

爬虫——模拟点击动态页面

动态页面的模拟点击: 以斗鱼直播为例:http://www.douyu.com/directory/all 爬取每页的房间名.直播类型.主播名称.在线人数等数据,然后模拟点击下一页,继续爬取 #!/usr/bin/python3 # -*- conding:utf-8 -*- __author__ = 'mayi' """ 动态页面的模拟点击: 模拟点击斗鱼直播:http://www.douyu.com/directory/all 爬取每页房间名.直播类型.主播名称.在线人数

爬虫——网站模拟登录

使用Selenium与PhantomJS模拟登录豆瓣:https://www.douban.com/ #!/usr/bin/python3 # -*- conding:utf-8 -*- __author__ = 'mayi' """ 模拟登录豆瓣:https://www.douban.com/ """ from selenium import webdriver # 调用环境变量指定的PhantomJS浏览器创建浏览器对象,executable

python爬虫 模拟登陆校园网-初级

最近跟同学学习爬虫的时候看到网上有个帖子,好像是山大校园网不稳定,用py做了个模拟登陆很有趣,于是我走上了一条不归路..... 先上一张校园网截图 首先弄清一下模拟登陆的原理: 1:服务器判定浏览器登录使用浏览器标识,需要模拟登陆 2: 需要post账号,密码,以及学校id python走起,我用的2.7版本,用notepad++写的,绑定python可以直接运行 由于是模拟网页登陆,需要导入urllib urllib2 cookielib库,前两个有与网页直接的接口,cookielib就是用来

Android模拟位置信息

Android模拟位置程序,俗称GPS欺骗,只能修改采用GPS定位的软件. 手机定位方式目前有4种:基站定位,WIFI定位,GPS定位,AGPS定位 常见的修改手法: 1. 抓包欺骗法,抓包改包欺骗服务器端, 但是得专门去针对某款app,而且现在很多app数据包都加密了 2. hook java层经纬度获取函数, 这个方法以前可以用,现在不行了 3. hook native层经纬度获取函数 4. 使用允许模拟地址位置信息(不是很通用有版本限制) 为了修改微信朋友圈地理位置信息,为了好玩 试过了上

CSU 1112: 机器人的指令【模拟题】

1112: 机器人的指令 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1858  Solved: 682 [Submit][Status][Web Board] Description 数轴原点有一个机器人.该机器人将执行一系列指令,你的任务是预测所有指令执行完毕之后它的位置. ·LEFT:往左移动一个单位 ·RIGHT: 往右移动一个单位 ·SAME AS i: 和第i 条执行相同的动作.输入保证i 是一个正整数,且不超过之前执行指令数 In

Regionals 2015 &gt;&gt; Europe - Central &gt;&gt;7325 - Book Borders【模拟】

Europe - Central >>7325 - Book Borders 题目链接:7325 题目大意:给你一个字符串(含空格),每行x个字符,将单词排列进去,单词不能断开,问每行第一个单词的长度时多少,注意加空格 题目思路:直接模拟.第一个for遍历[a,b],第二个大致为n/a.复杂度大概为nlogn. 开两个数组,v[i]记录i这个位置所属的单词开始位置,e[v[i]]记录第i个位置所属的单词的结束位置. 然后每次判断这一行结尾,所在位置.如果在两个单词中间,则将该单词视为下一行开始

GNS 3模拟防火墙ASA

[模拟环境] 所使用的GNS3版本为0.7.4,如果低于这个版本,有些版本会缺少些选项无法支持. [ASA]     ASA有2种模式的编译文件,分别为单模式和多模式,可选择使用.我使用的是单模式,我试用过多模式,不太好用. [配置] 打开GNS3,编辑→首选项→Qemu→ASA:     添加单模式:Identifier name:asa802-k8-sing(自己填名称,但不能是中文)RAM:256(使用默认的256)Number of NICs:6(网卡数量,默认是6)NIC model: