摘要:
例题 例题 例题 并查集,在一些有N个元素的集合应用问题中,我们通常是在开始时让每个元素构成一个单元素的集合,然后按一定顺序将属于同一组的元素所在的集合合并,其间要反复查找一个元素在哪个集合中 现在我们假定 fa[i] 表示第 i 个人的老大是谁 现在我们有甲,乙,丙三个人(分别用 a, b, c 阅读全文
摘要:
#include <bits/stdc++.h> using namespace std; int n, m, ans = 1;//n m 表示要约的数 ans调试函数递归用 clock_t start, finish; //计时器 //辗转相除法 适用于比较大的数 但是最好不要是高精度 % 的效率 阅读全文
摘要:
水 #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int N = 1e4 + 9; int n ; struct node{ int data; // 数值 int rank 阅读全文
摘要:
前缀和: 一维: #define N 10004 void _1(){ int n, a[N], ans[N]; scanf("%d",&n); for(int i = 1; i <= n; i++){scanf("%d",a+i);ans[i] += ans[i-1] + a[i] ;} // f 阅读全文