CSU1562-Fun House
来源:互联网 发布:强制起床闹钟软件 编辑:程序博客网 时间:2024/06/05 00:59
Fun House
Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 498 Solved: 176Description
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 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
Hint
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.
Source
题意:有一个地图,从一个点射出光线,若碰到镜子光线会反射,找到光线最终射到哪里
解题思路:dfs即可
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <map> #include <cmath> #include <set> #include <stack> #include <queue> #include <vector> #include <bitset> #include <functional> using namespace std; #define LL long longconst int INF = 0x3f3f3f3f;char ch[30][30];int dir[4][2]={{1,0},{0,1},{0,-1},{-1,0}};int n,m;void dfs(int x,int y,int d){if(ch[x][y]=='x') {ch[x][y]='&';return ;}if(ch[x][y]=='*'||ch[x][y]=='.') dfs(x+dir[d][0],y+dir[d][1],d);else if(ch[x][y]=='/'){if(d==0) dfs(dir[2][0]+x,y+dir[2][1],2);else if(d==1) dfs(dir[3][0]+x,dir[3][1]+y,3);else if(d==2) dfs(dir[0][0]+x,dir[0][1]+y,0);else dfs(dir[1][0]+x,dir[1][1]+y,1);}else{if(d==0) dfs(dir[1][0]+x,dir[1][1]+y,1);else if(d==1) dfs(dir[0][0]+x,dir[0][1]+y,0);else if(d==2) dfs(dir[3][0]+x,dir[3][1]+y,3);else dfs(dir[2][0]+x,y+dir[2][1],2);}}int main(){int cas=0;while(~scanf("%d%d",&m,&n)&&(n+m)){int x,y;for(int i=1;i<=n;i++){scanf("%s",ch[i]+1);for(int j=1;j<=m;j++)if(ch[i][j]=='*') {x=i,y=j;}}if(x==1) dfs(x,y,0);if(x==n) dfs(x,y,3);if(y==1) dfs(x,y,1);if(y==n) dfs(x,y,2);printf("HOUSE %d\n",++cas);for(int i=1;i<=n;i++) printf("%s\n",ch[i]+1);}return 0;}
- CSU1562 Fun House
- CSU1562-Fun House
- Fun House
- 1562: Fun House
- 1562:Fun House
- CSU 1562Fun House
- csu 1562 Fun House
- CSU 1562 Fun House
- Fun House CSU
- SDUT3184 Fun House(模拟)
- CSU 1562 — Fun House
- csu 1562: Fun House (DFS)
- CSU 1562 Fun House(直线搜索)
- fun
- fun
- FUN
- fun
- house
- 小狗吃骨头(DFS+剪枝)
- iOS多线程中的锁
- CodeForces #426 div2 A The Useless Tony
- 整合在线流程图设计器及遇到的问题(三)
- CSS3布局相关样式
- CSU1562-Fun House
- git 的使用
- sql的四种联接小总
- 微信小程序周报(第九期)-极乐科技
- Codeforces 834 B The Festive Evening
- 项目开发中git使用的那些事儿
- java线程数过高原因分析
- Python 网络爬虫与信息获取(二)—— 页面内容提取
- 免费视频教程:java经典面试题深度解析