版本比较
题解 P4675 【[BalticOI 2016 day1]Park】
正文
增加 5 行删除 5 行
12344567837 行未改动46474849505150515253545556575859606061626364656667686970707172737461 行未改动做题目时因为没有题解,自己调试了半天,于是想把自己的程序分享一下,给后来者参考参考。
# 进入正题这道题目运用到了[$\color{#ff0481}\boxed{\small\texttt{并查集}}$](https://www.luogu.org/problemnew/lists?name=&orderitem=pid&tag=47&content=0&type=)、$\color{#ff0481}\boxed{\small\texttt{离线}}$。 这道题目运用到了[$\color{#ff0481}\boxed{\small\texttt{并查集}}$](https://www.luogu.org/problemnew/lists?name=&orderitem=pid&tag=47&content=0&type=)、$\color{#ff0481}\boxed{\small\texttt{离线}}$。上述算法不清楚不要紧,我们慢慢来。
## 并查集并查集从字面意思上来理解,是一种支持**合并**与**查询**的数据结构。并查集的合并指的是将两颗有根树合并,查询指的是查询节点的根。37 行未改动
struct tree{ long long x,y,d; inline double operator - (struct tree tmp)
inline double operator - (struct tree tmp) { return sqrt((x-tmp.x)*(x-tmp.x)+(y-tmp.y)*(y-tmp.y))-d-tmp.d; }}t[MAXN];
struct man{ long long from,id,d;
inline bool operator < (const man &tmp) const { return d<tmp.d; }}w[MAXM];
struct cost{ long long a,b;double dis;
inline bool operator < (const cost &tmp) const { return dis<tmp.dis; }61 行未改动