设为首页 加入收藏

TOP

HDU 1885 Key Task 状态压缩+搜索(一)
2015-07-20 17:56:28 来源: 作者: 【 】 浏览:3
Tags:HDU 1885 Key Task 状态 压缩 搜索
点击打开链接

Key Task

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1176 Accepted Submission(s): 462


Problem Description The Czech Technical University is rather old ― you already know that it celebrates 300 years of its existence in 2007. Some of the university buildings are old as well. And the navigation in old buildings can sometimes be a little bit tricky, because of strange long corridors that fork and join at absolutely unexpected places.

The result is that some first-graders have often di?culties finding the right way to their classes. Therefore, the Student Union has developed a computer game to help the students to practice their orientation skills. The goal of the game is to find the way out of a labyrinth. Your task is to write a verification software that solves this game.

The labyrinth is a 2-dimensional grid of squares, each square is either free or filled with a wall. Some of the free squares may contain doors or keys. There are four di?erent types of keys and doors: blue, yellow, red, and green. Each key can open only doors of the same color.

You can move between adjacent free squares vertically or horizontally, diagonal movement is not allowed. You may not go across walls and you cannot leave the labyrinth area. If a square contains a door, you may go there only if you have stepped on a square with an appropriate key before.
Input The input consists of several maps. Each map begins with a line containing two integer numbers R and C (1 ≤ R, C ≤ 100) specifying the map size. Then there are R lines each containing C characters. Each character is one of the following:

\


Note that it is allowed to have
more than one exit,
no exit at all,
more doors and/Z??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vciBrZXlzIG9mIHRoZSBzYW1lIGNvbG9yLCBhbmQ8YnI+CmtleXMgd2l0aG91dCBjb3JyZXNwb25kaW5nIGRvb3JzIGFuZCB2aWNlIHZlcnNhLjxicj4KPGJyPgpZb3UgbWF5IGFzc3VtZSB0aGF0IHRoZSBtYXJrZXIgb2YgeW91ciBwb3NpdGlvbiAoobAqobEpIHdpbGwgYXBwZWFyIGV4YWN0bHkgb25jZSBpbiBldmVyeSBtYXAuIDxicj4KPGJyPgpUaGVyZSBpcyBvbmUgYmxhbmsgbGluZSBhZnRlciBlYWNoIG1hcC4gVGhlIGlucHV0IGlzIHRlcm1pbmF0ZWQgYnkgdHdvIHplcm9zIGluIHBsYWNlIG9mIHRoZSBtYXAgc2l6ZS4KCiAKPGJyPgoKT3V0cHV0CgpGb3IgZWFjaCBtYXAsIHByaW50IG9uZSBsaW5lIGNvbnRhaW5pbmcgdGhlIHNlbnRlbmNlIKGwRXNjYXBlIHBvc3NpYmxlIGluIFMgc3RlcHMuobEsIHdoZXJlIFMgaXMgdGhlIHNtYWxsZXN0IHBvc3NpYmxlIG51bWJlciBvZiBzdGVwIHRvIHJlYWNoIGFueSBvZiB0aGUgZXhpdHMuIElmIG5vIGV4aXQgY2FuIGJlIHJlYWNoZWQsIG91dHB1dCB0aGUgc3RyaW5nIKGwVGhlIHBvb3Igc3R1ZGVudCBpcyB0cmFwcGVkIaGxIGluc3RlYWQuIDxicj4KPGJyPgpPbmUgc3RlcCBpcyBkZWZpbmVkIGFzIGEgbW92ZW1lbnQgYmV0d2VlbiB0d28gYWRqYWNlbnQgY2VsbHMuIEdyYWJiaW5nIGEga2V5IG9yIHVubG9ja2luZyBhIGRvb3IgZG9lcyBub3QgY291bnQgYXMgYSBzdGVwLgoKIAo8YnI+CgpTYW1wbGUgSW5wdXQKCjxwcmUgY2xhc3M9"brush:java;">1 10 *........X 1 3 *#X 3 20 #################### #XY.gBr.*.Rb.G.GG.y# #################### 0 0
Sample Output
Escape possible in 9 steps.
The poor student is trapped!
Escape possible in 45 steps.

每个位置有16种状态,可以用一个vis三维数组表示每个点的16种状态,对于四种锁,每种锁用一位来表示,有钥匙标记为1,否则标记为0.然后bfs搜索一下就行了。
//109MS	556K
#include
  
   
#include
   
     #include
    
      #include
     
       #define M 107 using namespace std; int n,m,s,t; int dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}}; char g[M][M]; bool vis[M][M][17]; char up[4]={'B','Y','R','G'}; char low[4]={'b','y','r','g'}; struct n
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 4417 划分树+二分 下一篇POJ训练计划3277_City Horizon(扫..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: