ICode9

精准搜索请尝试: 精确搜索
  • AcWing 1073. 树的中心2022-05-22 01:00:07

    每个节点到其余节点的最长距离可以分为向上走和向下走两类: 向下走:dfs_down,求每个子节点向下走的最长距离,用子节点维护父节点 向上走:dfs_up,分为两类,一类是父节点向下走的的最长距离,一类是向上走的,因为父节点向下走的最长距离可能经过此节点,所以对于每个节点需要维护向下走的最大值

  • AcWing 220. 最大公约数2022-05-21 16:01:35

    题目传送门 一、视频教程 https://www.bilibili.com/video/BV1cP4y1c7q8 二、解题思路 最开始读错题,成了: \(1<=x,y<=N\),并且\(gcd(x,y)=1\)有多少数对? 这不就是在计算\(\displaystyle \sum_{i=1}^{N}φ(i)\)吗? 其实本题不是说\(gcd(x,y)=1\),而是说\(gcd(x,y)=p\),其中\(p\)是质

  • AcWing 算法提高课 数字三角形模型 左上到右下走两次的dp2022-05-19 22:02:46

    对AcWing 1015. 摘花生(走一次)的拓展 二维网格,左上到右下走两次,或者左上到右下再到左上,求收集数总和的最大值。 等价于求两条路径,和行走方向是无关的。 故都可以等价为从左上同时走。 例题: AcWing 1027. 方格取数AcWing 275. 传纸条 构建dp的方法是,三位dp,第三位记录同时走的步数(x和

  • AcWing 1289. 序列的第k个数2022-05-18 14:02:51

    题目传送门 一、疑问:能不能一个数列,即是等差数列又是等比数列? 结论:一个数列如果是即是等差又是等比,那么它必然是一个全等数列 证明: 设三个连续数字\(a\ b \ c\), 等差数列,所以\(a+c=2b\) ① 等比数列,所以\(\frac{b}{a}=\frac{c}{b}\),所以\(b^2=ac\) ② 将\(a=2b-c\)代入② \(b^2

  • 高精度计算模板 -感谢acwing2022-05-17 21:35:10

    高精度加 1 // C = A + B, A >= 0, B >= 0 2 vector<int> add(vector<int> &A, vector<int> &B) 3 { 4 if (A.size() < B.size()) return add(B, A); 5 6 vector<int> C; 7 int t = 0; 8 for (int i = 0; i &

  • AcWing 145. 超市2022-05-17 17:04:57

    // // Created by Kaede on 2022/5/17 // Problem: Acwing 145 // #include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <vector> namespace DisjointSet { class disjointSet {

  • [AcWing 894] 拆分-Nim游戏2022-05-16 00:31:24

    点击查看代码 #include<iostream> #include<cstring> #include<unordered_set> using namespace std; const int N = 110; int n; int f[N]; int sg(int x) { if (f[x] != -1) return f[x]; unordered_set<int> S; for (int i = 0; i <

  • [AcWing 891] Nim游戏2022-05-15 18:02:21

    点击查看代码 #include<iostream> using namespace std; int main() { int n; cin >> n; int res = 0; while (n --) { int x; scanf("%d", &x); res ^= x; } if (res) puts("Yes");

  • acwing周赛502022-05-15 15:33:49

    题目链接 1.缺少的数 模拟 \(O(n)\) 可以使用桶排序,将未出现的字母输出即可 时间复杂度 遍历一次O(n) C++代码 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 1e5 + 10; int n; int num[N]; int main() { cin >> n;

  • acwing周赛512022-05-15 15:32:33

    题目链接 1.上车 算法(暴力枚举) \(O(n)\) 只需要判断出车辆空余是否大于二即可 时间复杂度 暴力一遍即可,复杂度位\(O(n)\) C++ 代码 #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N = 1e5 + 10; int n, m, k; int main() { cin.t

  • [AcWing 890] 能被整除的数2022-05-14 22:00:41

    点击查看代码 容斥原理 (转自 OI Wiki) 证明:(用到了 $ (1 - 1)^{m} $ 的二项展开)

  • [AcWing 887] 求组合数 III2022-05-14 16:01:06

    复杂度 $ g(n) \ log(n) $ (来自 OI WiKi) 总体复杂度 $ 20 \times 10^{5} \times log(10^{5}) \times log(10^{18}) = 4 \times 10^{7} $ 点击查看代码 #include<iostream> using namespace std; typedef long long LL; int p; int qmi(int a, int k) { int res = 1;

  • 2022.5.14 AcWing每日一题2022-05-14 09:34:26

    签到难度 双指针 贪心 如果是 nlogn 的双指针算法,可以采取从左到右也可以从右到左,但是,如果时 n^2 的暴力模拟,只能从左到右。 从右向左,采用双指针,i记录a数组需要向左移动的数字(i,j所指不相同时),i,j所指相同时,直接向下移动,同时,如果j指到了被i记录过的数字,也要直接跳过。 #include <

  • 2022.5.13 AcWing每日一题2022-05-13 09:00:11

    模拟 #include <bits/stdc++.h> using namespace std; const int N = 20; int a[N], b[N]; int t; bool check(int a[], int b[]) { int w = 0, l = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (a[i] > b[j]) w++; if

  • [AcWing 878] 线性同余方程2022-05-11 20:32:49

    复杂度 $ O(log(n)) $ 总体复杂度 $ 10^{5} \times log(2 \times 10^{9}) \approx 4 \times 10^{6} $ 点击查看代码 #include<iostream> using namespace std; typedef long long LL; int exgcd(int a, int b, int & x, int & y) { if (!b) { x = 1, y =

  • 2022.5.11 AcWing每日一题2022-05-11 09:01:16

    思维 每两个名字之间以 小于等于 相连,如果出现前面的名字字典序大于后面的名字, 可以消除等于情况,即消除不确定性。 需要注意的是,用双重循环遍历的时候,确定第一个名字在位置i,枚举第二个名字位置j;只要从i到j之间有一个链接消除了不确定性,i和j之间的大小关系就会被确定下来。这就是代

  • acwing 91. 最短Hamilton路径2022-05-10 13:01:38

    状压dp,模板 f[i][j]表示以i为当前状态,j为终点的路径长度,属性:min #include<bits/stdc++.h> using namespace std; const int N = 21,M = 1<<20; int f[M][N],weight[N][N]; int main(){ int n; cin>>n; for(int i=0;i<n;i++) for(int j=0;j<n;j+

  • [AcWing 875] 快速幂2022-05-09 13:33:17

    复杂度 $ O(log(k)) $ (k 是指数) 总体复杂度 $ log(2 \times 10^{9}) = 9 \times log(20) \approx 40 $ 点击查看代码 #include<iostream> using namespace std; typedef long long LL; LL qmi(int a, int b, int p) { LL res = 1; while (b) { if (b & 1)

  • [AcWing 874] 筛法求欧拉函数2022-05-09 12:01:07

    复杂度 $ O(n) $ 总体复杂度 $ 10^{6} $ 点击查看代码 #include<iostream> using namespace std; const int N = 1e6 + 10; typedef long long LL; int primes[N], cnt; int eulers[N]; bool st[N]; void get_eulers(int n) { eulers[1] = 1; for (int i = 2; i <= n

  • 【位运算】AcWing 801. 二进制中1的个数(lowbit)2022-05-08 10:03:40

    AcWing 801. 二进制中1的个数 题解 用lowbit可以找到,最后一个1的位置。 通过lowbit计算每个数二进制1的个数,复杂度O(logn),n个数,一共O(nlogn) #include <iostream> #include <cstdio> const int N = 1e5+10; int a[N]; int lowbit(int x) { return x & -x; } int cnt(int

  • [AcWing 866] 试除法判定质数2022-05-08 00:04:07

    复杂度 \(O(\sqrt{n})\) 点击查看代码 #include<iostream> using namespace std; bool is_prime(int x) { if (x < 2) return false; for (int i = 2; i <= x / i; i ++) { if (x % i == 0) return false; } return true; } i

  • [AcWing 859] Kruskal算法求最小生成树2022-05-07 15:32:49

    复杂度 \(O(m*log(m))\) 点击查看代码 #include<iostream> #include<algorithm> using namespace std; const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f; int n, m; int p[N]; int res, cnt; struct Edge { int a, b, w; bool operator< (const Edg

  • [AcWing 854] Floyd求最短路2022-05-07 13:35:47

    复杂度 \(O(n^{3})\) 点击查看代码 #include<iostream> using namespace std; const int N = 210, INF = 1e9; int n, m, k; int d[N][N]; void floyd() { for (int k = 1; k <= n; k ++) for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++)

  • [AcWing 851] spfa求最短路2022-05-07 10:33:01

    点击查看代码 #include<iostream> #include<cstring> #include<queue> using namespace std; const int N = 1e5 + 10; int n, m; int h[N], e[N], ne[N], w[N], idx; int dist[N]; bool st[N]; void add(int a, int b, int c) { e[idx] = b; w[idx] = c

  • AcWing 253. 普通平衡树2022-05-07 10:03:30

    题目传送门 一、题目解析 平衡树,\(Treap\) 众所周知\(Treap = BST + heap\) 堆不多说了。 说说这个\(BST\),就是说一个根节点\(p\),左儿子一定小于他,右儿子大于它。 也就是\(BST\)的中序遍历是严格单调递增的。 那么就可以进行一些操作了。 左旋与右旋 首先为了维护这个\(BST\)我

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有