ICode9

精准搜索请尝试: 精确搜索
  • [AcWing 785] 快速排序2022-09-15 22:30:21

    第一篇博客诶!!! 点击查看代码 #include<iostream> using namespace std; const int N = 100010; int n; int q[N]; void quick_sort(int q[], int l, int r){ if(l >= r) return; //只有一个数或者没有数时则不用去遍历了 //int x = q[l]; //会超时 有两组数据

  • AcWing算法提高课 最小生成树2022-09-13 10:00:52

    一般使用kruskal(克鲁斯卡尔)(mlogm) 对于稀疏图,用朴素prim(n^2) prim:每次选择和当前已经构建出的连通块相连,且权重最小的边,加入当前连通块。 一共需要扩展(n-1)次      kruskal:基于并查集。先将所有边从小到大排序,然后枚举每条边,如果边的两个端点还不联通,则将当前边加入最

  • AcWing 860.染色法判断二分图2022-09-08 21:30:49

    题目链接:https://www.acwing.com/problem/content/862/ 放AC代码 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N = 1e5+10, M = 2e5+10;//因为是无向图所以边的数量*2 4 int e[M], ne[M], h[N], cnt; 5 int color[N]; 6 7 void add(int u, int v) 8

  • dp----状态机模型2022-09-03 21:04:18

    《需求引出》 《情况一:》 在一般的dp问题中,我们的当前项都是可以由前一项推出的, 但是在一些情况下我们要用到前前项的情况,这个时候可以将这个情况当做一个状态表示出来,进行转移    其中0表示:f[i][0]:在第i家店铺,不偷时的最大值 其中1表示:f[i][1]:在第i家店铺,偷时的最大值 转载

  • Acwing 第 66 场周赛 A-C2022-08-27 22:03:15

    2A,来晚 + 中间有事,第三题没写,但是写第三题的时候也感觉犯迷糊,读懂题意就好了 A AcWing 4606. 奇偶判断 题意:判断末位是偶数还是奇数 跳过   B AcWing 4607. 字母补全 题意:一段包含问号的字符序列,可以将问号改为任何字符,使一段长度为26的区间包括['A','Z']之间的所有字符 挨个遍历

  • acwing第65场周赛2022-08-21 22:01:29

    1.最大价值 原题链接:https://www.acwing.com/problem/content/4606/ 思路 经典双指针 代码: #include<iostream> #include<algorithm> #include<cstring> using namespace std; int main() { int n; cin >> n; while(n --) { int slen;

  • 【DP 记录】AcWing 734. 能量石2022-08-18 20:31:16

    传送门 给你几个物品,每种选一次,求最大价值,首先想到 01 背包,但是我们遇到了一个问题: 普通的 01 背包在选择物品时是不讲求顺序的,但在这道题中,物品的选择是有顺序的(即对最优解贡献有顺序),显然 \(O(n!)\) 枚举排列不可取,那我们能否提前确定好顺序,再来做背包呢? $\bullet\ $ 考虑从贪心

  • [AcWing 166] 数独2022-08-18 00:30:56

    DFS + 剪枝 + 位运算优化 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 9, M = 1 << N; int ones[M]; // ones[i]表示i的二进制数中1的个数 int map2[M]; // map2[i]表示log_2(i) int row[N], col[N], cell[3][3]; /

  • [AcWing 1118] 分成互质组2022-08-17 18:03:21

    DFS 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 50 + 10; int n; int a[N]; int len, ans = 1e9; vector<int> g[N]; // 判断数字y能否放到第k组 bool inline check(int k, int y) { for (auto& x : g[k])

  • [AcWing 1117] 单词接龙2022-08-17 13:33:46

    DFS 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 50 + 10; int n; string word[N]; int g[N][N]; // g[i][j]表示word[i]和word[j]的重合部分长度 int used[N]; // 记录单词的使用次数 int ans; void dfs(string s,

  • [AcWing 258] 石头剪刀布2022-08-16 21:35:02

    带扩展域的并查集 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6 + 10; int n, m; int p[N]; struct Node { int a, b; char op; } s[N]; int find(int x) { if (p[x] != x) p[x] = find(p

  • [AcWing 4290] 小希的迷宫2022-08-16 17:31:52

    并查集 + 树的判定 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6 + 10; int n; int p[N]; int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p[x]; } void merge(int a, int b) {

  • [AcWing 3409] 这是一棵树吗2022-08-16 14:32:42

    点击查看代码

  • AcWing-4507. 子数组异或和2022-08-13 21:02:13

    异或的一个性质:如果对一个数异或了两次就相当于不异或。 所以我们可以用前缀和预处理 \(a[i]\oplus =a[i-1]\) \(i\) 至 \(j\) 的异或和为 \(a[j]\oplus a[i-1]\) 该连续子数组的前一半元素的异或和等于其后一半元素的异或和。 即该连续子数组的异或和为 \(0\) 。 暴力的解法: #inc

  • [AcWing 4267] 可疑人员2022-08-12 00:02:01

    先合并集合,最后统计多少学生和 \(0\) 号学生属于同一集合 并查集 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6 + 10; int n, m; int a[N]; int p[N]; struct Node { int x, y; } s[N]; int find(int x) {

  • [AcWing 340] 通信线路2022-08-11 00:02:40

    二分 + 双端队列广搜 复杂度 \(m \cdot log(r - l) = 1 \times 10^4 \times log(10^9) = 3 \times 10^5\) 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6 + 10; const int M = 1e3 + 10; const int INF = 0x3f3f3f3

  • acwing 273. 分级 优先队列 贪心 构造2022-08-10 22:04:36

      给定长度为 NN 的序列 AA,构造一个长度为 NN 的序列 BB,满足: BB 非严格单调,即 B1≤B2≤…≤BNB1≤B2≤…≤BN 或 B1≥B2≥…≥BNB1≥B2≥…≥BN。 最小化 S=∑Ni=1|Ai−Bi|S=∑i=1N|Ai−Bi|。 只需要求出这个最小值 SS。 输入格式 第一行包含一个整数 NN。 接下来

  • AcWing 798. 差分矩阵2022-08-10 20:32:46

    二维差分 我们已经知道了一维差分如何去做,那么如果扩展到二维呢?这里就要引入二维差分了。 定义 给定一个数组 \(a\),构造一个数组 \(b\),使得 \(a\) 数组是 \(b\) 数组的前缀和数组,那么称 \(b\) 数组是 \(a\) 数组的差分数组。 作用 在 \(O(1)\) 的复杂度内将原矩阵中的任意子矩

  • [AcWing 1127] 香甜的黄油2022-08-09 01:04:54

    选一个起点,到其他点的最短距离之和最小 堆优化 dijkstra (太慢) 复杂度 \(O(n \cdot log(m) \cdot p) = 500 \times log(1450) \times 800 = 1.2 \times 10^7\) 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII;

  • AcWing算法基础课 手写哈希表2022-08-08 13:02:54

    开放地址法     M一般是N的十倍左右 find用于查找,看返回值是否为INF find用于插入,直接将待插入的值放到find返回的位置 会比unordered_set快5-10倍。

  • [AcWing 197] 阶乘分解2022-08-08 00:04:26

    点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6 + 10; int n; vector<int> primes; bool st[N]; void get_primes(int x) { for (int i = 2; i <= x; i ++) { if (!st[i]) prime

  • Acwing 1282 搜索关键词2022-08-07 18:01:48

    Acwing 1282 搜索关键词 题意: 给定 \(n\) 个长度不超过 \(50\)的由小写英文字母组成的单词,以及一篇长为\(m\)的文章。 请问,其中有多少个单词在文章中出现了。 思路: AC自动机模板题目 但是由于匹配到的是和当前的的字符串最长的字符位置,但是可能里面包含则其他单词,所以要不断的找

  • Acwing 1053 修复DNA2022-08-07 18:00:23

    Acwing 1053 修复DNA 题意: 给出\(n\)个字符串,这些字符串为致病因子,给出一个字符串,求将这些字符串处理成没有致病因子,最少需要改变多少个字符数量 请问,其中有多少个单词在文章中出现了。 思路: 利用AC自动机来实现多字符串匹配,设f[i][j]为,前i个字符,当前匹配到j。 注意标记哪些点不

  • [AcWing 179] 八数码2022-08-07 14:03:45

    A* 算法 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,string> PIS; const int N = 1e6 + 10; string start; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; char op[] = {'u', 'r&#

  • [AcWing 178] 第K短路2022-08-06 18:25:40

    A* 算法 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef pair<int,PII> PIPII; const int N = 1e6 + 10; int n, m, S, T, K; int h[N], rh[N], e[N], ne[N], w[N], idx; int d[N], c

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

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

ICode9版权所有