CSU 1562 Fun House(直線搜尋)
1562: 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 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
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.
題意:
給你一個地圖,一個射光點,一些鏡子\ /,讓你找到出射口。
POINT:
挺有意思的一題,就搜尋就好了。和Fzu的貓和老鼠有點像,是被迫轉彎的型別。
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define LL long long
char mp[33][33];
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int flag=0;
int n,m;
void dfs(int x,int y,int f)
{
if(x==1||x==n||y==1||y==m)
{
mp[x][y]='&';
flag=1;
return;
}
int b=0;
if(mp[x][y]=='\\')
b=1;
else if(mp[x][y]=='/')
b=-1;
if(b==0)
dfs(x+dir[f][0],y+dir[f][1],f);
else if(b==1)
{
if(f==0) f=1;
else if(f==1) f=0;
else if(f==2) f=3;
else f=2;
dfs(x+dir[f][0],y+dir[f][1],f);
}
else
{
if(f==0) f=3;
else if(f==1) f=2;
else if(f==2) f=1;
else f=0;
dfs(x+dir[f][0],y+dir[f][1],f);
}
}
int main()
{
int k=0;
while(~scanf("%d %d",&m,&n))
{
if(n==0&&m==0) break;
for(int i=1;i<=n;i++)
{
scanf("%s",mp[i]+1);
}
int bx,by;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(mp[i][j]=='*')
{
bx=i;
by=j;
break;
}
}
}
int now;
if(bx==1) now=0;
else if(bx==n) now=2;
else if(by==1) now=1;
else now=3;
dfs(bx+dir[now][0],by+dir[now][1],now);
printf("HOUSE %d\n",++k);
for(int i=1;i<=n;i++)
{
printf("%s\n",mp[i]+1);
}
}
}
相關文章
- CSU 1563 Lexicography (搜尋+組合數)
- 【Beam Search】波束搜尋的直觀解釋
- win10藍芽一直搜尋怎麼處理_win10藍芽一直在搜尋解決方法Win10藍芽
- Elasticsearch線上搜尋引擎讀寫核心原理深度認知-搜尋系統線上實戰Elasticsearch
- Steam全新搜尋功能上線 可按價格縮小搜尋範圍
- 最佳路徑搜尋(二):啟發式搜尋(代價一致搜尋(Dijkstra search),貪心搜尋,A*搜尋)
- 海量資料搜尋---搜尋引擎
- 搜狗搜尋推廣平臺下線
- 搜尋
- 搜尋引擎-03-搜尋引擎原理
- 谷歌上線資料搜尋引擎 Dataset Search谷歌
- 【Lintcode】1562. Number of RestaurantsREST
- 搜尋引擎es-分詞與搜尋分詞
- 點選搜尋框清空搜尋提示文字
- 網頁版“頭條搜尋”悄然上線,今日頭條想成為國內知名搜尋引擎網頁
- 直播系統程式碼,常用搜尋中搜尋歷史,搜尋推薦功能
- 搜尋策略
- vim搜尋
- 搜尋功能
- 搜尋技巧
- 搜廣推演算法校招面試:BOSS直聘 推薦搜尋系統工程師演算法面試工程師
- 20240713總結(搜尋專題,但是不想搜尋)
- Elasticsearch(ES)的高階搜尋(DSL搜尋)(上篇)Elasticsearch
- Elasticsearch(ES)的高階搜尋(DSL搜尋)(下篇)Elasticsearch
- win10搜尋框無限載入怎麼辦_win10搜尋框一直載入不出來如何解決Win10
- 搜尋的未來是精品搜尋 | a16z
- 直播開發app,實時搜尋、搜尋引擎框APP
- 谷歌搜尋用上BERT,10%搜尋結果將改善谷歌
- 啟發式搜尋的方式(深度優先,廣度優先)和 搜尋方法(Dijkstra‘s演算法,代價一致搜尋,貪心搜尋 ,A星搜尋)演算法
- Python之 常用查詢演算法:最小項搜尋、順序搜尋、二分搜尋Python演算法
- 谷歌自帶的線上工具和常用搜尋技巧谷歌
- 搜尋插入位置
- 搜尋/查詢
- Google搜尋技巧Go
- Elasticsearch 向量搜尋Elasticsearch
- Elasticsearch常用搜尋Elasticsearch
- 貪心+搜尋
- elasticsearch搜尋商品Elasticsearch