数据结构
bekote
这个作者很懒,什么都没留下…
展开
-
数据结构 || 偏移量并查集(食物链)
食物链动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说法是"2 X Y",表示X吃Y。 此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K...原创 2018-02-26 21:29:05 · 262 阅读 · 0 评论 -
数据结构 || 并查集判断树
#include<iostream> #include<algorithm> #include<vector> #define MAX 100000000 using namespace std; int ans; int pre[1000000]; int a[1000000]; int find(int x){ int r=x; while(pre[r]...原创 2018-02-17 15:07:12 · 130 阅读 · 0 评论 -
数据结构 || 带权并查集(堆积木)
Building BlockProblem DescriptionJohn are playing with blocks. There are N blocks (1 <= N <= 30000) numbered 1...N。Initially, there are N piles, and each pile contains one block. Then John do so...原创 2018-02-21 22:14:43 · 411 阅读 · 0 评论 -
数据结构 || 带权并查集(判断数列和)
InputLine 1: Two integers, N and M (1 <= N <= 200000, 1 <= M <= 40000). Means TT wrote N integers and FF asked her M questions.Line 2..M+1: Line i+1 contains three integer: Ai, Bi and ...原创 2018-02-22 20:38:08 · 155 阅读 · 0 评论 -
数据结构 || 逆向并查集
先建立最终状态,保存操作过程,逆序操作(如减边转化为加边)原创 2018-03-04 20:49:46 · 411 阅读 · 0 评论 -
数据结构 || 并查集模版
int find(int x){ int r=x; while(pre[r]!=r){ r=pre[r]; } int i=x,j; while(pre[i]!=r){ j=pre[i]; pre[i]=r; i=j; } return r; }int find(int x){ if(pre[x]==x)return x; else{ ...原创 2018-03-04 20:57:06 · 153 阅读 · 0 评论 -
数据结构 || 图论 || 并查集+最小生成树(kruskal)
Connect the CitiesProblem DescriptionIn 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connected with others, but most of them become disconnected....原创 2018-03-04 22:36:43 · 146 阅读 · 0 评论 -
补题向 | Concatenated Multiples(map int和string转换)
Concatenated Multiples 给出n个数和k,两个数组合而成一个新数,这个新数能被k整除,有多少个这样的组合 假如数13和2,k为4,组合成132,对k求余,可以看成130%k+2%k,要知道132%k是不是等于k,相当于求k-(130%k)等不等于2 在上面例子里,13后面加一个0是由2的位数决定的 存在一种特殊情况,自己和自己组合可以被k整除 使用map<...原创 2018-08-31 00:21:41 · 316 阅读 · 0 评论 -
补题向 | Maximal Intersection(multiset)
Maximal Intersection 给出n对数,代表一条线段的左右端点位置,求删去其中一条线段之后,剩余的线段交叉的长度最大是多少(剩余所有线段的公共部分) 对于一些交叉的线段,他们公共部分为最大的左端点到最小的右端点 如果线段不交叉,那么最大的左端点到最小右端点为负数,依题意,公共部分长度视为0 使用multiset,和set一样可以自动排序,不同点在于multiset中可...原创 2018-08-29 16:51:30 · 205 阅读 · 0 评论