随笔分类 - AcWing 每日一题
2023.6.8 AcWing LeetCode
摘要:AcWing 二分 + DFS树遍历 注意,虽然树中边的数量为顶点数-1,但是由于实际中将无向边存为两条有向边,所以数组开辟的边数个数要是顶点数的两倍。 #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int
2022.8.3
摘要:LeetCode 思维题 最小表示法 最小表示法题解 最小表示法: 最小表示法原理及实现在这篇blog中 AcWing 16进制读写 #include<bits/stdc++.h> using namespace std; int ans; int main() { while(scanf("%X"
2022.8.2 L:eetCode
摘要:LeetCode 模拟循环队列 https://leetcode.cn/problems/design-circular-queue/solution/672-by-sen-xm-n0on/ AcWing 想用getline实现一下,但是截取单词子串的时候取成 i = j 和 j = i 了,这样的
2022.7.31 LeetCode AcWing周赛
摘要:LeetCode BFS 层序遍历模板题 https://leetcode.cn/problems/maximum-level-sum-of-a-binary-tree/solution/1161-by-sen-xm-3q4t/ AcWing 周赛第二题 单点修改 + 区间修改 + 区间查询 如果暴
2022.7.30 LeetCode AcWing
摘要:LeetCode 建图 + 并查集 + (筛法求质数) 如果暴力的建图,跑dfs最大连通图,建图会成为瓶颈,O(n^2)。 但是考虑到,A、B两数,A、B分别与其非1非自身的因数相连,如果A、B之间联通,那么A、B相互联通的那个点为公因数。可以将时间复杂度从依赖数据量的大小转移到依赖数据按数据范围。
2022.7.29 LeetCode AcWing
摘要:LeetCode 模拟 特判 https://leetcode.cn/problems/valid-square/solution/593-mo-ni-by-sen-xm-73z6/ AcWing 思维题 对于A来说,其他蚂蚁碰头与否没有任何关系,即不与A碰头的蚂蚁可以看做相互之间直接穿过而不产生影
2022.7.28 LeetCode AcWing
摘要:LeetCode STL 模拟 https://leetcode.cn/problems/rank-transform-of-an-array/solution/1331-stl-by-sen-xm-w57d/ AcWing 贪心 如果有解,从大到小依次判断是否能加入部分和中使得部分和不会超过目标和
2022.7.27 LeetCode AcWing
摘要:LeetCode 模拟 + 字符串 题解如下: https://leetcode.cn/problems/fraction-addition-and-subtraction/solution/by-sen-xm-u2ak/ string转int: https://blog.csdn.net/xion
2022.7.26 LeetCode AcWing
摘要:LeetCode 实现跳表 主要参考了以下几篇Bolg: https://www.acwing.com/blog/content/15081/ https://www.jianshu.com/p/9d8296562806 https://www.acwing.com/blog/content/486
2022.7.25 LeetCode AcWing
摘要:LeetCode 题解如下: https://leetcode.cn/problems/complete-binary-tree-inserter/solution/919-by-sen-xm-2gev/ AcWing 模拟 #include <bits/stdc++.h> using namesp
2022.7.23 AcWing
摘要:AcWing (每日一题感觉有点简单了。) BFS + 试除法判定质数 #include <bits/stdc++.h> using namespace std; typedef long long LL; int T; LL x; LL ans; bool check(LL t) { for (L
2022.7.22 AcWing LeetCode
摘要:LCA 倍增 #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; int T; int n, m; int h[N], e[N * 2], ne[N * 2]; // f 为倍增函数,存储每个节点i,取j次父节点
2022.7.21 AcWing LeetCode
摘要:乘法原理 每个小数后面相乘的0,在结果的积中是不变的。 #include <bits/stdc++.h> using namespace std; int n, m; int ans; int main() { while (scanf("%d %d", &n, &m)) { ans = 0; if
AcWing 2022.7.20
摘要:链表模拟 + 队列模拟 可以用队列模拟,维护未弹出的数据和顺序。 也可以直接按题目要求维护循环队列,只需要单链表就够了。 队列: #include <bits/stdc++.h> using namespace std; const int N = 60; int T; int n; int ne[
AcWing 2022.7.19-2
摘要:类LCA问题 采用LCA思想,因为满二叉树的父子之间的大小关系确定了,所以不需要建图,直接用 /2 模拟追溯祖先的过程即可。 #include <bits/stdc++.h> using namespace std; int a, b; int main() { //cout << "pause"
AcWing每日一题 2022.7.19
摘要:DFS + 排序剪枝 排序剪枝:为了防止同一个序列被枚举多次,先排序,对于相同的数,只枚举出现的第一次。 对于dfs内部的排序,同样只枚举出现的第一次,但是是对于本次枚举出现的第一次,之前已经确定在序列中的不需要考虑。 由于每次枚举只考虑最先出现的那个,所以这个结构是可以迭代执行而不出错的。 #in
2022.5.20 AcWing每日一题
摘要:DFS 不是选出三条直线再检测,而是在运行的过程中,如果遇到了没有被前面的情况,选取垂直或平行的直线。 #include <bits/stdc++.h> using namespace std; typedef pair<int, int> PII; int n; vector<PII> cows;
2022.5.15 AcWing周赛第51场[补]
摘要:A 签到 https://www.acwing.com/problem/content/4422/ #include <bits/stdc++.h> using namespace std; int n; int p, q; int ans; int main() { scanf("%d", &n)
2022.5.14 AcWing每日一题
摘要:签到难度 双指针 贪心 如果是 nlogn 的双指针算法,可以采取从左到右也可以从右到左,但是,如果时 n^2 的暴力模拟,只能从左到右。 从右向左,采用双指针,i记录a数组需要向左移动的数字(i,j所指不相同时),i,j所指相同时,直接向下移动,同时,如果j指到了被i记录过的数字,也要直接跳过。
2022.5.13 AcWing每日一题
摘要:模拟 #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