
并查集
ChengYuQi621
北京邮电大学人工智能学院
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
P1551 亲戚
https://www.luogu.org/problemnew/show/P1551 并查集模板题 #include<cstdio> #include<cstring> #include<iostream> using namespace std; const int N=100005; int n,m,t,a,b,f[N],g[N]; char c; i...原创 2019-07-08 08:36:49 · 219 阅读 · 0 评论 -
P1194 买礼物
https://www.luogu.org/problem/P1194 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <queue> #include <stack> #include <cma...原创 2019-09-15 09:26:26 · 282 阅读 · 0 评论 -
P1197 [JSOI2008]星球大战
https://www.luogu.org/problem/P1197 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <queue> #include <stack> #include <cma...原创 2019-09-15 09:25:35 · 194 阅读 · 0 评论 -
APTX4869
#199. APTX4869 描述 提交 自定义测试 【题目描述】: 为了帮助柯南回到一米七四,阿笠博士夜以继日地研究APTX4869的解药。他得出了如下结果: 1.解药由n种原料构成; 2.对于两种不同的的原料a,b,它们之间有个影响值f(a,b); 3.需要把所有原料分成两部分X,Y,每部分中至少有一种原料; 4.解药的效果由分别属于X,Y的原料之间,最小的影响值决定,即 效果=min{f(...原创 2019-09-12 21:47:20 · 1176 阅读 · 0 评论 -
虫子的生活
#255. 虫子的生活 描述 提交 自定义测试 【题目描述】: Hopper教授正在研究一种稀有虫子的交配行为。他假设它们有两种性别并且它们只与异性交配。在他的实验中,很容易识别虫子和它们的交配行为,因为虫子背后印有编号。 实验中有一群虫子N只,虫子编号1至N。Hopper教授记录了交配行为M条,教授假设每个交配行为是一对异性虫子,请你判断教授的假设有没有错。 【输入描述】: 输入的第一行包含测...原创 2019-09-08 23:04:06 · 834 阅读 · 0 评论 -
疯狂的馒头
#16. 疯狂的馒头 描述 提交 自定义测试 【题目描述】: CQF十分喜欢吃馒头,兴奋之下他一下子买了N 个馒头请所有认识他的人吃。 但是CQF不喜欢白色,喜欢红色、黄色、绿色等鲜艳的颜色。于是他把所有白色的馒头排成一列。然后进行M 次染色操作。每个染色操作都是用一个神奇的刷子把连续的多个馒头染成特定的某种颜色。一个馒头最终的颜色是最后一次染它的颜色。如果一个馒头没有被染过色,那么它的颜色就是...原创 2019-09-08 09:32:57 · 282 阅读 · 0 评论 -
P2661 信息传递
https://www.luogu.org/problem/P2661 #include <iostream> #include <cstdio> using namespace std; const int N = 200010; int n, fa[N], ans = 0x3f3f3f3f; int get (int x, int &cnt) { //cnt记录...原创 2019-08-15 17:04:17 · 105 阅读 · 0 评论 -
P1892 [BOI2003]团伙
https://www.luogu.org/problemnew/show/P1892 #include<stdio.h> #include<string.h> const int N=100005; int n,m,i,ans,a,b,f[N],g[N]; char c; int find(int x) { if(f[x]==0) return x; else...原创 2019-07-09 21:19:02 · 181 阅读 · 0 评论 -
P1111 修复公路
看!题面被吃掉了!https://www.luogu.org/problemnew/show/P1111 按时间sort一遍,每次合并两个节点,显然如果原先不连通那么合并之后联通块数量– 然后如果n==1就输出当前时间return #include <cmath> #include <cstdio> #include <iostream> #include &l...原创 2019-07-03 23:12:00 · 344 阅读 · 0 评论 -
P1525 关押罪犯
看!题面被吃掉了! https://www.luogu.org/problemnew/show/P1525 淳朴的并查集~但因为它们带有权值,因此排序是必须的,我们要尽可能让危害大的罪犯在两个监狱里。 那么,再结合敌人的敌人和自己在一个监狱的规律合并。 当查找时发现其中两个罪犯不可避免地碰撞到一起时,只能将其输出并结束。 #include <cmath> #include <cs...原创 2019-07-03 23:09:40 · 169 阅读 · 0 评论 -
1074 食物链
看!题面被吃掉了! http://codevs.cn/problem/1074/ 带权并查集。。。。 注意关系 #include <cmath> #include <cstdio> #include <iostream> #include <algorithm> using namespace std; const int N=50005; int...原创 2019-07-03 23:06:44 · 247 阅读 · 0 评论 -
[NOI2002]银河英雄传说
看!题面被吃掉了。。。 [NOI2002]银河英雄传说:https://www.luogu.org/problemnew/show/P1196 fa[]数组维护两个编号之间的连通性,dis[]维护编号为i的战舰到fa[i]之间的距离,num[]维护编号为i的战舰所在的那一列有多少战舰。 #include #include #include #include using namespace ...原创 2019-07-03 22:59:41 · 385 阅读 · 0 评论 -
舒适的路线
1001 舒适的路线 2006年 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光。 Z小镇附近共有 N(1<N≤500)个景点(编号为1,2,3,…,N),这些景点被M(0<M≤5000)条道路连接着,所有道路都是双向的,两个景点之间可能有多条道路。也...原创 2019-07-08 08:44:07 · 185 阅读 · 0 评论 -
P1039 侦探推理
https://www.luogu.org/problemnew/show/P1039 #include<iostream> #include<cstring> #include<string> using namespace std; int n,m,p,fake[21],err,w[200],nx; string name[100],say[200]; s...原创 2019-09-25 18:02:52 · 310 阅读 · 0 评论