代码应用
是
蓝展展
这个作者很懒,什么都没留下…
展开
-
AcWing 158. 项链 (最小表示法,字符串)
闫总的代码,稍微改了改,注释了很多东西#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<char, int> PII;const int mod = 1e9 + 7;const int INF = 0x3f3f3f3f;const int N = 1e6 + 50;int n;char a[N], b[N];int get_min(char s[]){原创 2021-05-19 21:13:04 · 102 阅读 · 0 评论 -
2419. prufer序列
题目:https://www.acwing.com/problem/content/description/2421/题意: 求prufer代码:#include <bits/stdc++.h>#define lowbit(x) x&(-x)using namespace std;typedef pair<int, int> PII;typedef long long ll;const double DINF = 1e20;const double eps原创 2021-03-23 11:34:03 · 311 阅读 · 0 评论 -
高斯消元 (基本线代知识)
#include <iostream>#include <cstdio>#include <cmath>using namespace std;const int N = 15;int n;double a[N][N] , b[N][N];void gauss(){ for(int r = 1 , c = 1 ; c <= n ; c++) { int t = r; for(int i = r原创 2021-02-21 15:14:15 · 145 阅读 · 0 评论 -
B - Super Mancunian 并查集+思维
题目:https://vjudge.z180.cn/contest/423156#problem/B题意:给一个连通图,求当把一条边的花费归成0时的最小生成树,并且求最少花费的所有路径数量解析: 最小花费 = 并查集的最优解 - 最大路径的花费;当求数量的时候可以用最优解往下跑,当遇到小于最大边的时候,这条边就是最优解的一部分,把它并起来,反之,当大于最大边时,不减成零的时候他一定不是最优解,但是当减成零的时候,剩下的边一定是最优解,因为咱们用的是最优解往下跑的,不是最优解的都没有并起来,所以他是一种原创 2021-02-17 09:59:06 · 161 阅读 · 0 评论 -
覆盖的面积 线段树+理解转换
这个代码只是理解一下每个node存的东西是什么(以点来代指区间)#include <bits/stdc++.h>#define lowbit(x) x&(-x)using namespace std;typedef long long ll;typedef pair<int, int > PII;const ll llINF = 0x3f3f3f3f3f3f3f3f;const int INF = 0x3f3f3f3f;const double DINF =原创 2021-01-30 16:58:31 · 104 阅读 · 0 评论 -
曹冲养猪acwing(中国剩余定理)
题目:https://www.acwing.com/problem/content/1300/题意:中国剩余定理x = b1 (mod a1)x = b2 (mod a2)x = b3 (mod a3)…x = bi (mod ai)求最小的满足x的解解析:中国剩余定理: M是所有ai的乘积, mi是M / ai(出自己之外的所有数的乘积)ti是关于ai的逆元。 则答案 = SUM(bi * ti * mi);代码:#include <bits/stdc++.h>#def原创 2021-01-21 10:46:23 · 147 阅读 · 0 评论 -
欧几里得, 扩展欧几里得 Gcd, Exgcd
欧几里得算法:(辗转相除法)inline int Gcd(int a, int b){ if (b == 0) return a; return Gcd(b, a % b);}扩展欧几里得:ax + by = gcd(a, b)gcd(a, b) 是ax + by 的最小正整数解。怎样求一个x和y满足这个解呢:inline int Ex_gcd(int a, int b, int &x, int &y){ if (b == 0) {原创 2021-01-20 10:49:10 · 118 阅读 · 0 评论 -
反素数(用空多看一下)
题目:https://www.acwing.com/problem/content/200/对于任何正整数x,其约数的个数记作g(x),例如g(1)=1、g(6)=4。如果某个正整数x满足:对于任意的小于x的正整数 i,都有g(x)>g(i) ,则称x为反素数。例如,整数1,2,4,6等都是反素数。现在给定一个数N,请求出不超过N的最大的反素数。输入格式一个正整数N。输出格式一个整数,表示不超过N的最大反素数。数据范围1≤N≤2∗109解析: 找一个数,满足他的约数的个数是最多的原创 2021-01-19 15:26:52 · 143 阅读 · 0 评论 -
E - Envious Exponents 二进制+思维
题目:https://vjudge.z180.cn/contest/417619#problem/E题意:给你一个数n和k, 然后把它变成k个2的不同幂的和,并且大于n。分析: 把这个数转化成二进制,然后分情况讨论;1 cnt < k 时, 只需从低位到高位的0变1即可2 cnt == k 时, 先把这个数变大(可能cnt有变换),再变成 cnt = k(意思就是必须执行一次改变)3 cnt > k 时, 从低位找到第一个1前面的0, 将0变1, 然后将变1的这一位的所有低位变成0,原创 2021-01-18 16:33:54 · 108 阅读 · 0 评论 -
A - Abandoned Animal 搜索+思维thinkthink
题目:https://vjudge.z180.cn/contest/417619#problem/A题意:给你一个比较乱的购物清单,有在哪里购买的和购买了什么, 在此之前告诉你每个商店卖的是什么,问清单对不对,和有没有多种情况。解析:首先,自己把题目读错了,认为商品是有序的,然后一件商品找一个商店,然后再倒着找一遍,说实话,理解的非常错误┭┮﹏┭┮从0 到 n - 1个商店,每个商店把所有的商品都卖完(越早买越好),但是可能这个商店不卖这件商品,则清单有误,然后继续到下一个商店,但是不能一个商店就跑一原创 2021-01-18 15:12:24 · 143 阅读 · 0 评论 -
B - Blurred Pictures 二分+小细节(眼睛大)
题目:https://vjudge.z180.cn/contest/418003#problem/B题意: 一个正方形相片,有1*1的像素构成的,但是损伤了一些像素,给出每一行像素从一个地方到另一个地方的没有损坏的像素,从中割除最大的没有损坏的正方形相片。思路: 二分答案,判断答案是否可行,可行的话继续增大答案,否则减小答案;判断的过程是判断两侧是否满足自己二分的答案,有6种情况 (只列举最上面和最下面的横线)1) …………………… 这种情况不行原创 2021-01-18 11:54:47 · 327 阅读 · 0 评论 -
E - Rounding 思维+低智商(冬季集训补题)
题目:https://vjudge.z180.cn/contest/418003#problem/E题意:总共10000个人,做了一项调查,统计出了数据,但是把这个数据的所有结果都四舍五入了,问你找出结果的最大值和最小值,也有结果不对的情况解析:其实这个题目很简单,当时也想出了解决的方法,但是在应用最大值得时候没有想过来,┭┮﹏┭┮。干活:%因为每一个结果都是四舍五入的,那么每一个值(x)得范围都是在x - 50 到 x + 49 之间, 这是一定的,但是题目有约束条件,就是调查的总人数是100原创 2021-01-18 11:02:03 · 186 阅读 · 0 评论 -
D - Monument Tour 冬季集训补题
题目:https://vjudge.z180.cn/contest/418003#problem/D题意:一辆汽车往右走,如果左右有景点,则去哪个地方然后再返回自己第一次选的路,然后继续往右。#include <bits/stdc++.h>#define lowbit(x) (x & (-x))using namespace std;const int mod = 1e9 + 7;const int N = 2e5 + 50;const int INF = 0x3f3f3f原创 2021-01-18 09:41:13 · 217 阅读 · 0 评论 -
HDU - 5934 BOMB (考的是Tarjan的强连通)
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <stack>#include <queue>#include <map>#include <ti原创 2020-12-19 21:25:57 · 67 阅读 · 0 评论 -
Dijkstra 啦啦啦
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>#include <string>#include <cstring>#include <map>#include <utility>#include <queue>using namespa原创 2020-11-19 20:28:15 · 129 阅读 · 0 评论 -
Python第一个ac代码
while True: try: a, b, c, d = map(int, input().split()) if a * d == b * c: print('=') elif a * d > b * c: print('>') else: print('<') except: break原创 2020-10-24 13:36:04 · 206 阅读 · 0 评论 -
Problem E. Evaluations Gym - 101840E 很留皮的题
这是我的代码和我的搭档的代码的结合体,当然自己的代码根本不对,但是搭档改对了#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <string>#include <algorithm>#include <math.h>#include <stack>#include <que原创 2020-08-25 20:14:08 · 121 阅读 · 0 评论 -
Z algorithm(also exkmp algorithm)
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <string>#include <algorithm>#include <math.h>#define ll long long#define Fast_io ios::sync_with_stdio(false), cin.tie(0),原创 2020-08-19 09:01:20 · 112 阅读 · 0 评论 -
线段树扫描线模板(求面积和周长) Picture
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;const int N = 205;struct Line{ int st; //记录上下边 double s, e, x; //记录x的左右边 bool operator<(const Line &a) const { retu原创 2020-08-08 11:12:40 · 146 阅读 · 0 评论 -
敌兵布阵(不是为了做这个题,而是想知道tree应该开多大)
#include <istream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <limits.h>using namespace std;int arr[50005], tree[50005 * 4];void buildtree(int node, int start, int end){ if (start == end)原创 2020-08-03 14:29:28 · 104 阅读 · 0 评论 -
PTA上的题 :是否完全二叉搜索树 (30分)
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <malloc.h>struct node{ int data, num; struct node *l, *r;} * q[100];struct node *root = NULL;struct node *buildtree(struct node *root, int x){ i原创 2020-08-02 18:17:50 · 279 阅读 · 0 评论 -
Colored Sticks POJ - 2513(自己觉得调试的最麻烦的一题+不大理解hh)
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <limits.h>#include <algorithm>#include <math.h>#include <stack>using namespace std;int cnt = 1, x, y, deg[500001],原创 2020-07-31 11:16:11 · 123 阅读 · 0 评论 -
小鑫的城堡(并查集)啦啦啦
先附上正确的代码:#include #include <stdio.h>#include <stdlib.h>#include <string.h>#include #include <limits.h>#include <math.h>using namespace std;int f[100005];int getf(int v){if(v == f[v])return v;else{f[v] = getf(f.原创 2020-06-07 20:29:17 · 157 阅读 · 0 评论 -
最短路 自己觉得较快的(没有用栈优化的)
先附上代码#include #include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <limits.h>#include <memory.h>#include #define N 999999using namespace std;int main(){int n;scanf("%d", &n)原创 2020-06-02 19:49:02 · 159 阅读 · 0 评论 -
Pots 广度优先搜索
啥都不说。现附上代码(借鉴了一个学长“莫若诩殇”, 顿时感觉明白了)#include #include <stdio.h>#include <stdlib.h>#include #include #include <memory.h>#define N 1010struct node{int x, y, step;};int main(){int a, b, c;while(~scanf("%d %d %d", &a, &b,原创 2020-05-28 20:13:35 · 102 阅读 · 0 评论