Space Gophers 校賽排位

2021-10-09 20:43:49 字數 2752 閱讀 8079

題意:在乙個巨大的三維網格空間中建造 n 條垂直座標系的隧道,q 個詢問,詢問兩點之間是否可以通過隧道到達。

分析:考慮使用並查集維護,但是如何合併兩條隧道較難處理,因為這個網格空間的量級是 1e6 的,我們不可能每次都將整條隧道中的點合併。假設建了一條 (x,y,−1) 的隧道,如下圖加粗藍色柱體:

題解鏈結

寫完這個題給我的體會就是我缺少三維空間的想象能力。

然後還有 並查集可以寫乙個 struct ,這樣就會很方便。

還有乙個匿名函式,寫在主程式裡面,也很方便。

#include

using

namespace std;

const

int m =

1e6+20;

const

int n =

6e5+

100;

void

dbg(

)template

<

typename t,

typename..

. a>

void

dbg(t a, a.

.. x)

#define logs(x...)

int n,m;

struct node

node

(int _x,

int _y,

int _z):x

(_x),y

(_y),z

(_z)

bool

operator

<

(node a)

const};

struct disjoin

intfind

(int k)

bool

issame

(int x,

int y)

intunion_ver

(int x,

int y)

return0;

}}u;

intmain()

else

if(y ==-1

)else

mp[node

(x,y,z)

]= i;

}for

(auto it: mp))if

(!zx[y]

.empty()

) zx[y]=;

if(mp.

count

(node(-

1,y,tp.z)))

u.union_ver

(mp[

node(-

1,y,tp.z)

], id);}

for(

auto z:)if

(!yx[z]

.empty()

) yx[z]=;

if(mp.

count

(node(-

1,tp.y,z)))

u.union_ver

(mp[

node(-

1,tp.y,z)

], id);}

}else

if(tp.y ==-1

));if

(mp.

count

(node

(x,-

1,tp.z)))

u.union_ver

(mp[

node

(x,-

1,tp.z)

], id);}

for(

auto z :);

if(mp.

count

(node

(tp.x,-1

, z)))

u.union_ver

(mp[

node

(tp.x,-1

, z)

], id);}

}else);

if(mp.

count

(node

(x, tp.y,-1

))) u.

union_ver

(mp[

node

(x, tp.y,-1

)], id);}

for(

auto y :);

if(mp.

count

(node

(tp.x, y,-1

))) u.

union_ver

(mp[

node

(tp.x, y,-1

)], id);}

}}auto getid =[&

](node p)

;int q;

scanf

("%d"

,&q)

;for

(int i =

1; i<= q;

++i)

}return0;

}/*16

-1 1 1

3 -1 2

1 5 -1

5 5 -1

-1 5 5

-1 5 9

61 1 1 6 1 1

8 1 1 3 2 2

1 1 1 5 5 5

1 5 5 5 5 9

1 5 10 10 1 1

1 5 9 5 5 9

*/

sdut 3914 校賽 校賽

time limit 1000ms memory limit 65536kb problem description sdut 的校賽是從 2009 年開始的,康納每年看到比賽之後,往往就會喊一聲 ma ji ya ba ku nai 年份的縮寫 比如說 2009 年就會說 ma ji ya ba ...

SDUT 3914 校賽 校賽

time limit 1000ms memory limit 65536kb problem description sdut 的校賽是從 2009 年開始的,康納每年看到比賽之後,往往就會喊一聲 ma ji ya ba ku nai 年份的縮寫 比如說 2009 年就會說 ma ji ya ba ...

2017校賽題解

又是一年一度的校賽,三個人從出題到準備環境花了好幾天的時間。雖然也是蠻累的,期間出了一些小差錯,但總的來說還是蠻成功的 感覺比去年好一些,逃。一共出了7題,但是考慮到比賽時間比較緊張就砍掉了兩題 反正沒砍我的題,對了,關於 teddywang 同學在題面上黑我的情況表示強烈譴責,將在他不注意的時候實...