摘要:
P7072 [CSP-J2020] 直播获奖基本思想:求前几名是多少分。 #include<algorithm> #include<iostream> using namespace std; const int maxn=100010; int a[maxn]; int t[610]; int m 阅读全文
摘要:
P4995 跳跳!贪心思想,在石头中最大和最小来回跳。 #include<bits/stdc++.h> using namespace std; int main() { vector<int> h; int n; cin>>n; for (int i=1;i<=n;i++) { int x; ci 阅读全文
摘要:
P2240 【深基12.例1】部分背包问题按价值比从大到小排序,每次选择价值比大的全部物品,或按比例选取部分物品直到背包为空为止。 #include<bits/stdc++.h> using namespace std; struct node{ int zl; int jz; bool opera 阅读全文
摘要:
P1531 I Hate It区间最大值,区间查询最大值,单点更新,本解使用树状数组求解 #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; const int MAXN = 3e5; int a 阅读全文
摘要:
P1531 I Hate It区间最大值,区间查询最大值,单点更新 //P1531 I Hate It #include<cstdio> #include<algorithm> #include<iostream> using namespace std; #define lson l,m,rt<< 阅读全文
摘要:
P3374 【模板】树状数组 1题解:线段树的单点更新,区间查询,注意线段树的结点个数是原数组的4倍 #include<iostream> #include<cstdio> using namespace std; long long s[2000100],a[501000],n,m,dx,dy; 阅读全文
摘要:
P3406 海底高铁题解区间修改可以用差分思想,统计每个点出现次数用前缀和,最后取最小值 #include<bits/stdc++.h> using namespace std; const int maxn=100009; int p[maxn],v[maxn]; long long ans; i 阅读全文
摘要:
P5638 【CSGRound2】光骓者的荣耀题解:由题意可知枚举i=1~n-k,且i+k~n两段的和求最小值,纯暴力时间O(n2),此题会TLE,预处理前缀和,可以加快两点的和求解时间为O(n),注意数据大小要long long 类型。 #include<bits/stdc++.h> using 阅读全文
摘要:
P1115 最大子段和 /* P1115 最大子段和 */ #include<cstdio> #include<iostream> using namespace std; int main() { // freopen("p1115_2.in","r",stdin); int ans; int s 阅读全文
摘要:
前缀和是一种重要的预处理,能大大降低查询的时间复杂度。最简单的一道题就是给定 n 个数和 m 次询问,每次询问一段区间的和。求一个 O(n + m) 的做法。用 O(n) 前缀和预处理,O(m) 询问。一、一维前缀和主要代码 for(int i = 1; i <= n; ++i) sum[i] = 阅读全文
摘要:
gcd指的是greatest common divisor就是最大公约数。lcm指的是Least Common Multiple,即最小公倍数。一、最大公约数最大公约数是数论中一个重要的概念设a、b不全为零,同时整除a、b的整数称为他们的公约数,显然a、b的公约数只有有限多个,我们将其中最大的一个称 阅读全文
摘要:
算术基本定理可表述为:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积 ,这里P1<P2<P3......<Pn均为质数,其中指数ai是正整数。这样的分解称为 N 的标准分解式。质因子分解代码 #include<iostream> using namespace st 阅读全文
摘要:
P3367 【模板】并查集 #include<iostream> #include<algorithm> using namespace std; const int maxm=10010; int pre[maxm]; int n,m; void make()//初始化 { for (int i= 阅读全文
摘要:
P1551 亲戚是一题经典的并查集的应用,有亲戚关系的为一个集合。 #include<iostream> using namespace std; const int maxn=5010; int pre[5010]; int n,m,p; void make()//初始化 { for (int i 阅读全文