
数据结构——并查集
手可摘星辰!!
这个作者很懒,什么都没留下…
展开
-
程序自动分析 并查集+离散化
题意给你一组数 i,j,e.如果e=1那么,i j存在关系,如果e=1,,i,j 没有关系。问事是否冲突。解题方法如果e=1,把这些数用并查集存起来,e=0时 判断i,j是否在一个集合。关键点 i,j 过大,需要离散化#include<iostream>#include<cstdio>#include<cstring>#include<...原创 2019-08-08 13:58:13 · 98 阅读 · 0 评论 -
银河英雄传说 带权并查集
题意:有一个划分为N列的星际战场, 各列依次编号为 1, 2, ···, N. 有 N 艘战舰, 也依次编号为 1 - N, 初始时, 第 i 号战舰在第 i 列.T条指令, 有两种格式.M i j, 表示让第 i 号战舰所在列的全部战舰保持原有的顺序, 接在第 j 号战舰所在列的尾部.C i j, 表示询问第 i 号战舰与第 j 号战舰是否处在同一列中, 如果在同一列中, 他们之...原创 2019-08-08 15:07:48 · 119 阅读 · 0 评论 -
POJ 1703 Find them,Catch them
#include<iostream>#include<cstdio>#include<cstring>const int MAXN=200020;int n,m;int set[MAXN];int set_find(int d){ if(set[d]<0) return d; else retu...原创 2019-08-06 21:15:16 · 229 阅读 · 0 评论 -
POJ1988 Cube Stacking
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>const int maxn=100010;int set[maxn],cnt[maxn],top[maxn];int set_find(int p){ if(set[p]<0) ...原创 2019-08-06 21:16:33 · 69 阅读 · 0 评论 -
POJ 2236 Friends
#include <bits/stdc++.h>using namespace std;const int N = 30000;int f[N + 1], cnt[N + 1];int n, m;void Init(){ for (int i = 1; i <= n; i++) { f[i] = i; cnt[i] = ...原创 2019-08-06 21:19:42 · 101 阅读 · 0 评论