青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設計空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6

Finding Nemo

Posted on 2007-01-14 01:58 oyjpart 閱讀(1358) 評論(2)  編輯 收藏 引用 所屬分類: ACM/ICPC或其他比賽

Finding Nemo
Time Limit:2000MS? Memory Limit:30000K
Total Submit:1965 Accepted:370

Description
Nemo is a naughty boy. One day he went into the deep sea all by himself. Unfortunately, he became lost and couldn't find his way home. Therefore, he sent a signal to his father, Marlin, to ask for help.
After checking the map, Marlin found that the sea is like a labyrinth with walls and doors. All the walls are parallel to the X-axis or to the Y-axis. The thickness of the walls are assumed to be zero.
All the doors are opened on the walls and have a length of 1. Marlin cannot go through a wall unless there is a door on the wall. Because going through a door is dangerous (there may be some virulent medusas near the doors), Marlin wants to go through as few doors as he could to find Nemo.
Figure-1 shows an example of the labyrinth and the path Marlin went through to find Nemo.


We assume Marlin's initial position is at (0, 0). Given the position of Nemo and the configuration of walls and doors, please write a program to calculate the minimum number of doors Marlin has to go through in order to reach Nemo.

Input
The input consists of several test cases. Each test case is started by two non-negative integers M and N. M represents the number of walls in the labyrinth and N represents the number of doors.
Then follow M lines, each containing four integers that describe a wall in the following format:
x y d t
(x, y) indicates the lower-left point of the wall, d is the direction of the wall -- 0 means it's parallel to the X-axis and 1 means that it's parallel to the Y-axis, and t gives the length of the wall.
The coordinates of two ends of any wall will be in the range of [1,199].
Then there are N lines that give the description of the doors:
x y d
x, y, d have the same meaning as the walls. As the doors have fixed length of 1, t is omitted.
The last line of each case contains two positive float numbers:
f1 f2
(f1, f2) gives the position of Nemo. And it will not lie within any wall or door.
A test case of M = -1 and N = -1 indicates the end of input, and should not be processed.

Output
For each test case, in a separate line, please output the minimum number of doors Marlin has to go through in order to rescue his son. If he can't reach Nemo, output -1.

Sample Input

8 9
1 1 1 3
2 1 1 3
3 1 1 3
4 1 1 3
1 1 0 3
1 2 0 3
1 3 0 3
1 4 0 3
2 1 1
2 2 1
2 3 1
3 1 1
3 2 1
3 3 1
1 2 0
3 3 0
4 3 1
1.5 1.5
4 0
1 1 0 1
1 1 1 1
2 1 1 1
1 2 0 1
1.5 1.7
-1 -1

Sample Output

5
-1

第一次用priority_queue 發現效率還不錯~
居然1y了 很是驚訝的說 rp突然好起來了?
我是從Nemo向Marlin搜索的 采用優先隊列的方式就能找到最少的過門方式
細節部分還是要注意~~
Solution:
//by Optimistic
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
const int MAXINT = 2000000000;
const int N = 210;
struct Point{int x, y, p;}; //坐標,權值(經過門的個數)
bool wall[N][N][2], door[N][N][2], end[N][N], seted[N][N]; //墻壁,門,可直達點,標記
Point start;????????????????? //起點(Nemo)
int nw, nd, xh, yh;?????????? //墻的個數,門的個數,x的最高值,y的最高值(限定搜索范圍)
struct cmp
{
public: inline bool operator()(const Point& a, const Point& b) ?{return a.p > b.p;}
};
priority_queue <Point, vector<Point>, cmp> pq; //優先隊列
void set_end(int x, int y) //設置可直達點(不通過任何門)
{
?end[x][y] = 1;
?if(x-1 <= xh && x-1 >= 0 && y <= yh && y >= 0 && wall[x][y][1] == 0?
??&& door[x][y][1] == 0 && !end[x-1][y])???set_end(x-1, y);
?if(x <= xh && x >= 0 && y-1 <= yh && y-1 >= 0 && wall[x][y][0] == 0
??&& door[x][y][0] == 0 && !end[x][y-1])???set_end(x, y-1);
?if(x+1 <= xh && x+1 >= 0 && y <= yh && y >= 0 && wall[x+1][y][1] == 0
??&& door[x+1][y][1] == 0 && !end[x+1][y])??set_end(x+1, y);
?if(x <= xh && x >= 0 && y+1 <= yh && y+1 >= 0 && wall[x][y+1][0] == 0
??&& door[x][y+1][0] == 0 && !end[x][y+1])??set_end(x, y+1);
}?
void init()
{
?int i, x, y, d, t, j;
?double dx, dy;
?memset(wall, 0, sizeof(wall));
?memset(door, 0, sizeof(door));
?memset(end, 0, sizeof(end));
?yh = -MAXINT; xh = -MAXINT;
?for(i = 0; i<nw; i++) {
??scanf("%d%d%d%d", &x, &y, &d, &t);
??if(x > xh) xh = x;
??if(y > yh) yh = y;
??if(d == 0) {
???for(j = 0; j<t; j++) {
????wall[x+j][y][0] = 1;
???}
??}
??else {
???for(j = 0; j<t; j++) {
????wall[x][y+j][1] = 1;
???}
??}
?}
?for(i = 0; i<nd; i++) {
??scanf("%d%d%d", &x, &y, &d);
??if(x > xh) xh = x;
??if(y > yh) yh = y;
??door[x][y][d] = 1;
??wall[x][y][d] = 0;??? //門要把墻覆蓋 sample中可以看出來
?}
?cin >> dx >> dy;
?start.x = (int)dx, start.y = (int)dy, start.p = 0; //設置起點 初始化權值為0
?memset(seted, 0, sizeof(seted));
?set_end(0, 0); //設置可直達點(不通過任何門)
?yh++; xh++;
}
void work()
{
?if(start.x < 0 || start.x >= 200 || start.y < 0 || start.y >= 200 || xh <0 || yh <0)? //特殊情況
?{?printf("0\n");??return ;?}
?memset(seted, 0, sizeof(seted));
?while(!pq.empty()) pq.pop();
?pq.push(start);??????????????????????? //起點入列
?seted[start.x][start.y] = 1;
?while(!pq.empty()) {
??Point cur = pq.top();????????????? //取權值最大的點
??pq.pop();
??if(end[cur.x][cur.y] == 1) { printf("%d\n", cur.p); return;} //找到解
??int x= cur.x, y = cur.y;
??Point now;
??if(x-1 <= xh && x-1 >= 0 && y <= yh && y >= 0 && wall[x][y][1] == 0 && !seted[x-1][y]) { //左搜索
???if(door[x][y][1] == 1) now.p = cur.p + 1;
???else now.p = cur.p;
???now.x = x -1;???now.y = y;
???pq.push(now);
??}
??if(x <= xh && x >= 0 && y - 1 <= yh && y-1 >= 0 && wall[x][y][0] == 0 && !seted[x][y-1]) { //下搜索
???if(door[x][y][0] == 1) now.p = cur.p + 1;
???else now.p = cur.p;
???now.x = x;???now.y = y-1;
???pq.push(now);
???seted[now.x][now.y] = 1;
??}
??if(x+1 <= xh && x+1 >= 0 && y <= yh && y >= 0 && wall[x+1][y][1] == 0 && !seted[x+1][y]) { //右搜索
???if(door[x+1][y][1] == 1) now.p = cur.p + 1;
???else now.p = cur.p;
???now.x = x + 1;???now.y = y;
???pq.push(now);
???seted[now.x][now.y] = 1;
??}
??if(x <= xh && x >= 0 && y+1 <= yh && y+1 >= 0 && wall[x][y+1][0] == 0 && !seted[x][y+1]) { //上搜索
???if(door[x][y+1][0] == 1) now.p = cur.p + 1;
???else now.p = cur.p;
???now.x = x;???now.y = y+1;
???pq.push(now);
???seted[now.x][now.y] = 1;
??}
?}
?printf("-1\n"); //無解
}
int main()
{
?while(scanf("%d %d", &nw, &nd), !(nw == -1 && nd == -1)) {
??init();
??work();
?}
?return 0;
}

Feedback

# re: Finding Nemo  回復  更多評論   

2008-12-08 17:42 by lala
拉拉,你左搜索忘標記啦

# re: Finding Nemo  回復  更多評論   

2008-12-09 12:50 by alpc12
好像是啊。。。汗。。
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲高清激情| 国产精品午夜在线| 亚洲午夜国产成人av电影男同| 欧美午夜免费影院| 嫩模写真一区二区三区三州| 久久久久天天天天| 久久久久久夜精品精品免费| 久久精品视频在线观看| 久久免费国产| 欧美高清在线精品一区| 欧美激情一区二区三区蜜桃视频 | 亚洲每日更新| 亚洲乱码国产乱码精品精| 亚洲精品永久免费| 在线综合+亚洲+欧美中文字幕| 亚洲一区二区不卡免费| 亚洲欧美资源在线| 欧美专区福利在线| 亚洲国产二区| 亚洲成人在线视频播放 | 久久在线91| 久久综合图片| 欧美电影免费观看高清完整版| 欧美色精品在线视频| 国产一区二区精品丝袜| 亚洲美女黄网| 欧美亚洲视频一区二区| 久久久久久久性| 国产精品国产三级国产aⅴ9色| 韩国欧美国产1区| 亚洲一二三级电影| 欧美大片国产精品| 亚洲自拍偷拍视频| 欧美精品国产精品日韩精品| 国产日韩精品电影| 在线一区日本视频| 欧美韩日亚洲| 欧美在线视频免费观看| 欧美伦理一区二区| 在线播放亚洲一区| 欧美诱惑福利视频| 免费日本视频一区| 亚洲综合社区| 麻豆九一精品爱看视频在线观看免费| 蜜桃久久av| 中文网丁香综合网| 欧美成人久久| 精品不卡一区二区三区| 亚洲在线视频观看| 美女精品视频一区| 欧美在线视频免费播放| 欧美日韩综合网| 亚洲黄色小视频| 午夜精品在线| 夜夜嗨一区二区| 久久亚洲精品欧美| 最新国产の精品合集bt伙计| 欧美一区二区三区免费视| 欧美精品在线播放| 亚洲国产日韩在线一区模特| 欧美在线视频免费播放| 最新日韩在线| 毛片一区二区| 亚洲三级影院| 日韩亚洲一区二区| 久久婷婷亚洲| 欧美国产欧美亚洲国产日韩mv天天看完整 | 欧美一区亚洲| 欧美日韩岛国| 欧美人与性禽动交情品| 欧美一区二区三区免费大片| 欧美另类videos死尸| 亚洲视频在线一区| 欧美日韩高清在线观看| 亚洲激情成人在线| 亚洲高清视频在线观看| 免费观看成人鲁鲁鲁鲁鲁视频| 亚洲精美视频| 欧美日韩国产三区| 国内自拍亚洲| 亚洲一区二区三区免费观看| 一区二区三区四区五区视频| 亚洲欧美日韩国产成人| 久久久久久高潮国产精品视| 性欧美大战久久久久久久久| 亚洲欧美日韩国产综合| 一区二区三区欧美激情| 欧美第十八页| 欧美日韩国产123区| 亚洲高清不卡av| 欧美日韩一区二区三区在线观看免 | 欧美一区二区三区视频在线| 亚洲欧美在线免费| 日韩视频一区二区三区在线播放免费观看| 韩日精品在线| 国产精品videosex极品| 国产欧美一区二区精品仙草咪| 蜜月aⅴ免费一区二区三区| 欧美日韩高清在线一区| 亚洲男人第一网站| 亚洲毛片在线| 久久亚洲精品一区| 中文有码久久| 亚洲国产精品成人一区二区| 99亚洲一区二区| 亚洲欧美电影在线观看| 亚洲日本aⅴ片在线观看香蕉| 亚洲麻豆av| 久久视频免费观看| 在线一区二区三区做爰视频网站| 亚洲国产老妈| 日韩午夜免费视频| 麻豆久久久9性大片| 亚洲在线不卡| 国产精品亚洲成人| 国产深夜精品福利| 免费在线看一区| 免费国产自线拍一欧美视频| 国产在线一区二区三区四区| 欧美另类亚洲| 欧美在线free| 亚洲美女电影在线| 国内久久精品视频| 欧美成人a视频| 久久精品免费播放| 欧美成人一二三| 久久久久网址| 亚洲免费人成在线视频观看| 欧美一级专区| 久久国产精品电影| 欧美色欧美亚洲另类七区| 国产亚洲精品综合一区91| 99视频国产精品免费观看| 另类酷文…触手系列精品集v1小说| 久久成人综合视频| 尤物99国产成人精品视频| 国产日韩欧美亚洲| 久久久久久久久久久成人| 久久视频一区二区| 久久亚洲欧洲| 亚洲欧美资源在线| 在线亚洲国产精品网站| 久久精品国产一区二区三| 黑人巨大精品欧美一区二区小视频| 亚洲婷婷综合久久一本伊一区| 久久福利一区| 久久国产精品久久久久久久久久| 欧美一区激情视频在线观看| 欧美激情网友自拍| 久久久久国产精品www| 久久国产精品久久久久久电车 | 国产欧美一区二区三区久久人妖| 国产精品美女主播| 午夜精品偷拍| 国产精品国产三级国产普通话三级| 国产在线精品成人一区二区三区| 国产视频在线一区二区| 亚洲在线电影| 精品成人在线| 亚洲一区日本| 欧美高清视频一区二区| 久久国产精品久久久久久| 中文成人激情娱乐网| 亚洲美女av在线播放| 欧美在线视频免费观看| 欧美日韩一区综合| 国产嫩草影院久久久久| 国产精品福利在线| 亚洲国产日韩欧美在线动漫| 鲁大师成人一区二区三区| 亚洲国产日韩一级| 久久精品一区二区国产| 亚洲人成久久| 亚洲欧美国产高清| 国产揄拍国内精品对白| 亚洲精品久久久久久下一站 | 欧美乱大交xxxxx| 一区二区欧美视频| 国产自产2019最新不卡| 免费黄网站欧美| 在线观看不卡| 亚洲国产欧美久久| 亚洲精品欧美日韩专区| 夜夜精品视频一区二区| 激情综合五月天| 亚洲第一页中文字幕| 欧美在线综合| 亚洲理论在线| 国产午夜精品美女毛片视频| 欧美噜噜久久久xxx| 老鸭窝毛片一区二区三区| 亚洲一区二区三区免费视频| 欧美日韩一区二区三区在线| 亚洲国产一区在线观看| 午夜日韩在线观看| 亚洲精品国产视频| 欧美色大人视频| 亚洲一区二区影院| 日韩一区二区精品在线观看| 欧美精品一区三区|