03 2022 档案

摘要:1 /**\ 2 https://ac.nowcoder.com/acm/contest/26077/1005 3 从第i列第n行, 第1行m列添加起点, 然后bfs寻找能够分割两个点的墙 4 5 注意: 6 1、方向只能上下左右,因为对角线仍然可以穿过 7 2、处理图的数据的时候可以将-1的墙标记 阅读全文
posted @ 2022-03-21 19:51 std&ice 阅读(99) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://ac.nowcoder.com/acm/contest/26077/1004 3 最短路dijstra,既然从a -> b -> c最长,等价求b ->a + b -> c 4 枚举中继点 然后求出最短路的和的最大值即可 5 \**/ 6 #include <bit 阅读全文
posted @ 2022-03-21 18:02 std&ice 阅读(79) 评论(0) 推荐(0) 编辑
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 1e3 + 10; 4 int n, d[N]; //n个数 离散化后数组 5 struct node { 6 int x, id; 7 bool operator<( 阅读全文
posted @ 2022-03-20 11:05 std&ice 阅读(82) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://codeforces.com/contest/522/problem/D 3 离线查询, 按照右端点小的排前面, 4 使用p[x] 记录a[x]出现相同值的前一个位置, p[x]当作线段树的坐标, x - p[x]为值, 5 olgN进行加点, 然后查询 6 \** 阅读全文
posted @ 2022-03-10 10:32 std&ice 阅读(74) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://codeforces.com/problemset/problem/1609/C 3 一堆数相乘是质数,其中只有一个是质数, 4 统计左边的1的个数,右边1的个数,累加即可 5 \**/ 6 #include <bits/stdc++.h> 7 using name 阅读全文
posted @ 2022-03-09 17:54 std&ice 阅读(74) 评论(0) 推荐(0) 编辑
摘要:#include <bits/stdc++.h> using namespace std; const int N = 1009; int n; int a[N], f[N]; signed main() { ios::sync_with_stdio(false); cin >> n; for(in 阅读全文
posted @ 2022-03-09 10:58 std&ice 阅读(61) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 每组物品有若干个,同一组内的物品最多只能选一个 3 \**/ 4 #include <bits/stdc++.h> 5 using namespace std; 6 const int N = 1e3 + 9; 7 int n, m, v[N][N], w[N][N], s[N]; 阅读全文
posted @ 2022-03-09 10:54 std&ice 阅读(61) 评论(0) 推荐(0) 编辑
摘要:/**\ n种物品,第i种物品重量wi,价值vi,物品ci个,背包容量为m 例如某物品a,价值v,重量w,数量c个。 假设c=13,有13这样子的物品,我们使用二进制拆分,将13拆分为几个整数的和 拆成1、2、4、6,这样子1~13中任何的数都能由任意两个数组成。 for (int i = 1; i 阅读全文
posted @ 2022-03-09 10:48 std&ice 阅读(75) 评论(0) 推荐(0) 编辑
摘要:1 #include <iostream> 2 #define int long long 3 using namespace std; 4 const int mx = 1e7 + 9; 5 int n, m, dp[mx], w[mx], v[mx]; 6 signed main() { 7 c 阅读全文
posted @ 2022-03-09 10:34 std&ice 阅读(70) 评论(0) 推荐(0) 编辑
摘要:普通版本 /**\ f[i][j] 表示 前i件物品容量为j时最大价值 \**/ #include <bits/stdc++.h> using namespace std; const int N = 1010; int n, m, v[N], w[N], f[N][N]; signed main( 阅读全文
posted @ 2022-03-09 10:29 std&ice 阅读(70) 评论(0) 推荐(0) 编辑
摘要:#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define go continue #define int long long #define PII pair<int, int> 阅读全文
posted @ 2022-03-08 11:12 std&ice 阅读(103) 评论(0) 推荐(0) 编辑
摘要:/**\ https://ac.nowcoder.com/acm/problem/14526 01背包问题变种 \**/ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define 阅读全文
posted @ 2022-03-07 23:01 std&ice 阅读(71) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://codeforces.com/contest/1646/problem/C 3 题意给出一个数n,选择阶乘数和2次幂数的组合成n,求使用个数最小 4 两种做法: 5 1、dfs 暴力搜索(这道题dfs快点) 6 2、二进制状态压缩枚举 7 \**/ 8 #inclu 阅读全文
posted @ 2022-03-07 17:02 std&ice 阅读(93) 评论(0) 推荐(0) 编辑
摘要:1 for(int i = 0; i < (1 << n); i++) //0~2^n-1个状态 2 { 3 for(int j = 0; j < n; j++) 4 { 5 if(i & (1 << j)) //check每一位 6 { 7 8 } 9 } 10 } 阅读全文
posted @ 2022-03-07 16:58 std&ice 阅读(82) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 记录操作1的最后一次出现的地方,(前面操作都没有用), 3 然后对比他的下一次操作二的最大值(这里处理一个后缀最大值即可) 4 \**/ 5 #include <bits/stdc++.h> 6 using namespace std; 7 #define fi first 8 # 阅读全文
posted @ 2022-03-04 17:51 std&ice 阅读(100) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://www.luogu.com.cn/problem/P3386 3 二分图最大匹配匈牙利算法: 4 假设左部是男孩,右部是女孩 5 1、对于一个男孩子,如果他喜欢女孩y,女孩y没有配偶,就在一起 6 2、如果y有配偶了,x还是想去挖一手墙脚,y也不是什么好女人, 7 阅读全文
posted @ 2022-03-04 15:10 std&ice 阅读(91) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://codeforces.com/problemset/problem/1623/C 3 核心代码:运过来的石子够mid个,将a[i]全部甩过去,不然就把多出来的分到后面 4 int add = min(a[i], aa[i] - x) / 3; 5 \**/ 6 #i 阅读全文
posted @ 2022-03-04 09:49 std&ice 阅读(78) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://codeforces.com/contest/1426/problem/C 3 先自增再进行复制,这样最优,把一个数从1变成x,需要x-1次。 4 然后暴力枚举一遍,找到最小值就行了 5 \**/ 6 #include <bits/stdc++.h> 7 using 阅读全文
posted @ 2022-03-03 22:10 std&ice 阅读(68) 评论(0) 推荐(0) 编辑
摘要:1 int primes[N], cnt; // primes[]存储所有素数 2 bool st[N]; // st[x]存储x是否被筛掉 3 4 void get_primes(int n) 5 { 6 for (int i = 2; i <= n; i ++ ) 7 { 8 if (!st[i 阅读全文
posted @ 2022-03-03 15:18 std&ice 阅读(75) 评论(0) 推荐(0) 编辑
摘要:1 #include <bits/stdc++.h> 2 #define int long long 3 using namespace std; 4 const int N = 105; 5 const int mod = 1e7 + 9; 6 int n, k; 7 struct node { 阅读全文
posted @ 2022-03-03 15:14 std&ice 阅读(65) 评论(0) 推荐(0) 编辑
摘要:int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a,int b) { return a / gcd(a, b) * b; } 阅读全文
posted @ 2022-03-03 15:09 std&ice 阅读(70) 评论(0) 推荐(0) 编辑
摘要:乘法 1 #include <bits/stdc++.h> 2 using namespace std; 3 vector<int> mul(vector<int> &A, vector<int> &B) 4 { 5 vector<int> C(A.size() + B.size()); 6 7 f 阅读全文
posted @ 2022-03-03 15:03 std&ice 阅读(61) 评论(0) 推荐(0) 编辑
摘要:整数二分 1 /**\ 2 check()函数用来检查是否具有某种性质 3 r = mid 适用于答案往左逼近的情况 4 l = mid 适用于区间答案往右逼近的情况(例如最小最大值) 5 \**/ 6 int bs1(int l, int r) 7 { 8 while (l < r) 9 { 10 阅读全文
posted @ 2022-03-03 14:49 std&ice 阅读(89) 评论(1) 推荐(0) 编辑
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 #define fi first 4 #define se second 5 #define go continue 6 #define woc puts(""); 7 #define int l 阅读全文
posted @ 2022-03-03 12:15 std&ice 阅读(82) 评论(0) 推荐(0) 编辑
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 #define fi first 4 #define se second 5 #define go continue 6 #define woc puts(""); 7 #define int l 阅读全文
posted @ 2022-03-03 11:42 std&ice 阅读(69) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://codeforces.com/problemset/problem/1622/C 3 贪心: 4 先将数组排序,要么减小a[1]值,要么从后面开始变后面的数->a[1],枚举x y就可 6 后附公式证明 5 \**/ 6 #include <bits/stdc++. 阅读全文
posted @ 2022-03-01 23:42 std&ice 阅读(96) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 https://codeforces.com/contest/1627/problem/C 3 想要满足能够赋值的条件,必须所有点的度都不能>3 4 那么树退化成了链,就op记下输出格式,然后ans记录dfs的结果 5 由于链式 2 3 2 3 就满足prime path 6 \* 阅读全文
posted @ 2022-03-01 22:25 std&ice 阅读(89) 评论(0) 推荐(0) 编辑
摘要:1 /**\ 2 线段树:区间查询 区间修改 3 input: 4 5 5 5 1 5 4 2 3 6 2 2 4 7 1 2 3 2 8 2 3 4 9 1 1 5 1 10 2 1 4 11 output: 12 11 13 8 14 20 15 \**/ 16 #include <bits/s 阅读全文
posted @ 2022-03-01 09:12 std&ice 阅读(65) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示