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

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 閱讀(1354) 評論(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>
            久久精品国产亚洲一区二区三区| 亚洲欧美区自拍先锋| 久久婷婷综合激情| 久久大综合网| 亚洲第一级黄色片| 亚洲国产日韩综合一区| 欧美日韩播放| 欧美综合国产| 久久久噜噜噜久久中文字免| 亚洲精品小视频| 一区二区三区回区在观看免费视频| 国产精品高清网站| 久久青草久久| 欧美日韩不卡视频| 久久精品国产综合| 欧美国产在线观看| 久久黄金**| 欧美高清在线观看| 欧美一区二区视频97| 麻豆国产va免费精品高清在线| 宅男噜噜噜66国产日韩在线观看| 欧美一区久久| 一区二区三区毛片| 久久久精品动漫| 亚洲制服av| 美女视频黄a大片欧美| 午夜视频在线观看一区| 久热精品视频在线观看| 欧美一区二区三区日韩| 欧美成人精品激情在线观看 | 久久九九久久九九| 亚洲图片欧洲图片日韩av| 久久爱www.| 亚洲欧美日韩视频二区| 欧美韩国在线| 蜜臀va亚洲va欧美va天堂| 国产精品美女午夜av| 亚洲黄色影院| 亚洲电影下载| 久久国产精品久久w女人spa| 亚洲综合精品四区| 欧美精品午夜视频| 亚洲第一久久影院| 伊人春色精品| 欧美一区二粉嫩精品国产一线天| 亚洲无限乱码一二三四麻| 蜜桃av一区二区| 老司机精品视频一区二区三区| 国产精品日韩欧美一区二区三区 | 亚洲在线成人| 欧美日韩国产在线| 91久久久在线| 亚洲精品无人区| 蜜桃伊人久久| 亚洲国产你懂的| 亚洲人成在线影院| 麻豆av一区二区三区| 女同一区二区| 在线日韩欧美| 免费欧美日韩国产三级电影| 欧美a级在线| 亚洲成人资源网| 久久一区视频| 亚洲高清不卡在线观看| 亚洲片在线观看| 欧美精品黄色| 亚洲美女精品一区| 亚洲一区二区三区精品在线观看| 欧美日韩一区二区三区| 一区二区三区四区国产精品| 亚洲综合国产激情另类一区| 国产精品一区在线观看| 欧美在线日韩| 欧美大片在线看免费观看| 亚洲精品国产无天堂网2021| 欧美另类一区| 正在播放亚洲| 久久男人资源视频| 亚洲国产视频a| 欧美日韩午夜精品| 午夜精品美女自拍福到在线| 久久久久久黄| 亚洲精品视频在线| 国产精品久久影院| 久久九九久久九九| 亚洲精品一区二区网址| 午夜一级久久| 亚洲第一黄网| 国产精品www.| 久久精品视频在线看| 亚洲国产精品久久久久婷婷老年| 亚洲午夜久久久久久久久电影院 | 欧美国产日本在线| 亚洲一区二区三区在线观看视频| 久久久噜久噜久久综合| 亚洲精品欧美激情| 国产精品自拍三区| 米奇777超碰欧美日韩亚洲| 一区二区三区你懂的| 久久久综合网站| 一区二区三区四区五区视频| 国产亚洲美州欧州综合国| 欧美国产三区| 久久高清福利视频| 一区二区三区鲁丝不卡| 欧美激情一区三区| 久久精品道一区二区三区| 亚洲精品一级| 国内精品模特av私拍在线观看| 欧美噜噜久久久xxx| 久久久久国内| 亚洲综合社区| 99riav1国产精品视频| 久久综合图片| 欧美一区二区三区视频在线| 9久re热视频在线精品| 在线免费观看视频一区| 国产日韩欧美黄色| 国产精品久久久久9999吃药| 欧美高清视频| 久久免费偷拍视频| 久久成人羞羞网站| 亚洲免费影视| 亚洲视频在线免费观看| 亚洲精选中文字幕| 亚洲国产日韩欧美综合久久| 欧美成在线观看| 狼狼综合久久久久综合网| 久久久久国色av免费看影院| 欧美一级电影久久| 午夜精品久久| 亚洲欧美伊人| 午夜免费日韩视频| 午夜一区在线| 欧美一区2区三区4区公司二百| 亚洲一区免费在线观看| 亚洲一区二区不卡免费| 一区二区三区四区在线| 亚洲视频在线看| 亚洲伊人一本大道中文字幕| 亚洲深夜福利在线| 亚洲免费在线观看| 亚洲欧美日韩国产中文| 亚洲欧美日韩精品久久奇米色影视 | 黑人巨大精品欧美一区二区小视频| 国产精品久久久久久久久久尿| 欧美日韩一级片在线观看| 欧美精品在线看| 欧美日韩一卡| 国产精品影院在线观看| 国产亚洲成av人在线观看导航| 国产亚洲精品资源在线26u| 激情一区二区| 亚洲精品乱码久久久久久蜜桃91| 一本久久青青| 午夜视频一区二区| 久久久久久伊人| 欧美v日韩v国产v| 亚洲人成网站精品片在线观看 | 久久影院午夜论| 亚洲丶国产丶欧美一区二区三区| 亚洲欧洲日韩女同| 国产精品99久久久久久久女警| 亚洲一区激情| 久久综合久久久| 欧美日韩日韩| 国产一区二区三区四区在线观看| 在线日韩欧美| 亚洲男人的天堂在线aⅴ视频| 久久成人在线| 亚洲国产精品va| 亚洲网站啪啪| 久久婷婷国产综合精品青草| 欧美精品www在线观看| 国产精品视频免费观看www| 精品999在线播放| 亚洲午夜精品国产| 免费观看亚洲视频大全| 一区二区欧美日韩| 久久香蕉精品| 国产精品久久一级| 亚洲精品视频二区| 久久精品二区三区| 日韩一区二区免费看| 久久久久久久综合日本| 国产精品九九久久久久久久| 禁久久精品乱码| 亚洲午夜精品| 亚洲电影自拍| 欧美专区在线| 国产精品免费aⅴ片在线观看| 亚洲二区三区四区| 欧美一区二区三区在线| 亚洲精品乱码久久久久| 久久这里有精品15一区二区三区 | 久久九九99视频| 国产精品区二区三区日本| 日韩视频―中文字幕| 老司机午夜精品视频在线观看| 亚洲午夜电影|