03 2022 档案
摘要:裴蜀定理: 对任意的a,b,有 a*x+b*y = gcd(a,b);当b=0,有 gcd(a,b) = a; 当b≠0: b*y + (a - [a/b]*b)*x = gcd(a,b); b*y + a*x - [a/b]*b*x = gcd(a,b); a*x + b*(y-[a/b]*x)
阅读全文
摘要:能用到拓扑排序的前提: 必须是有向无环图。 如果有环,那么根本不可能形成拓扑排序; 算法流程: 用队列来执行 ,初始化讲所有入度为0的顶点入队。 主要由以下两步循环执行,直到不存在入度为 0 的顶点为止 选择一个入度为 0 的顶点,并将它输出;删除图中从顶点连出的所有边。循环结束, 若输出的顶点数小
阅读全文
摘要:首先用一个结构体存放原始的键值和下标。 然后遍历该结构体数组,如果当前遍历的节点的键值的绝对值没有在前面出现过,那么就再开一个数组用来存该节点的编号,并且标记为出现过,防止后续再次存他的下标。否则如果出现过,那么就再开一个数组存之前出现过的节点的下标。然后将头节点往后移,h = next[h] 如此
阅读全文
摘要:解释看这位大神的:链接 #include <bits/stdc++.h> using namespace std; const int N = 100010; int q[N]; bool st[N]; int n; int main() { cin >> n; for(int i = 0; i <
阅读全文
摘要:这题考察的就是数据结构里面的插入排序和归并排序的每一步的操作和流程。 可惜我太菜了。考试的时候做不出来! #include <bits/stdc++.h> using namespace std; const int N = 110; int a[N], b[N]; int n; int main(
阅读全文
摘要:正着跑一边,然后反着跑的把所有边的方向调换一下就好了。在图基础上加n再方向,这样很方便!orz!!! #include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i = 0; i < int(n); i++) #de
阅读全文
摘要:1/A题: https://codeforces.com/contest/1650/problem/A 这题其实很简单的,因为要同时删除两个数,我们看看我们最终要得到的数在这组数中的什么位置,如果在奇数位,那么就一定可以通过删除数字来得到。 #include <iostream> #include
阅读全文
摘要:写题的时候还是太紧张了,心态不够好,导致审题不清,慌慌张张。怎么办呢??? #include <iostream> using namespace std; int main() { string s; cin >> s; int leng = s.size(), flag = 0; for(int
阅读全文
摘要:#include <iostream> #include <cstring> using namespace std; const int N = 1010, INF = 0x3f3f3f3f; int l[N], r[N], val[N], n; int cnt[N], max_depth; vo
阅读全文
摘要:1/A题: https://codeforces.com/contest/1649/problem/A 这一题其实很简单,就是要求最左边和最右边的最小距离(只能跨一次水,no more than once!!!) #include <iostream> #include <cstring> usin
阅读全文
摘要:#include <iostream> using namespace std; int main(){ char op; int sad = 0, happy = 0, unhappy = 0, a = 0, b = 0; while(cin >> op) { if(op == '$') brea
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 10010; struct Peo { double housenum, area; }people[N]; struct Fam { int id
阅读全文
摘要:#include <iostream> #include <queue> using namespace std; const int N = 40; struct node { int data; node *lchild; node *rchild; }; int last[N], in[N];
阅读全文
摘要:给定一棵树,找出从根节点到叶节点的最长路径(如果有多个最长路径,输出节点数字小的那个); #include <iostream> #include <cstring> using namespace std; const int N = 10010; int h[N], e[N], ne[N], i
阅读全文
摘要:开两个数组,一个数组存物品的数量,一个数组代表箱子,表示第i个箱子的已经存的容量。 #include <iostream> using namespace std; const int N = 1010; int q[N], a[N]; int n; int main() { cin >> n; f
阅读全文
摘要:#include <iostream> using namespace std; const int N = 40; int q[N]; int k, n; void dfs(int st, int cnt, int total) { if(total == n) { k++; cout << n
阅读全文
摘要:这题我想到的就是用二进制,不过我的代码只能拿12分,去网上搜了一下别人的AC代码,有点不理解,但是感觉还行。 #include <iostream> #include <cmath> using namespace std; int main() { int n, m; cin >> n >> m;
阅读全文
摘要:对n行样例边判断边输出,先遍历每个字符判断逗号和句号的前面3个字符是否为ong。是的话开始倒序遍历空格,将第三个空格的下标进行存储,然后正序遍历到存储位置,后面拼接上qiao ben zhong.,否则直接输出Skipped #include <iostream> #include <cstring
阅读全文
摘要:我们用一个二维数组存数据。用g[i][0]存第i个学校的总人数。 然后 我们 以行为学校编号,展开每个学校的人数。 从第一列到最后一列依次由上往下编号。 #include <iostream> using namespace std; const int N = 110; int g[N][N];
阅读全文
摘要:这题实际上是模拟除法;上马原课的时候领悟到了,hh #include <iostream> using namespace std; int main() { int x; cin >> x; int ans = 0, cnt = 0; while(ans < x) { ans = ans * 10
阅读全文
摘要:首先创建一个二维数组,然后将输入的字符串按从左到右的顺序依次从二维数组的倒数第一列开始装入,装满装第二列,以此类推.... #include <iostream> #include <cstring> using namespace std; const int N = 1010; char g[N
阅读全文
摘要:暴力穷举!!! 注意前导0,还有 0 也算一个数,不能用 while(year) 判断循环结束 要不然 0 就加不上了。 #include <iostream> #include <cstring> using namespace std; int judge(int y) { int a[10],
阅读全文
摘要:暴力!!!冲冲冲!!! #include <iostream> #include <cstring> using namespace std; int main() { string A, B; getline(cin, A); getline(cin, B); for(int i = 0; i <
阅读全文
摘要:这题我傻了。。 #include <iostream> #include <algorithm> using namespace std; typedef long long LL; int n; void merge(LL &a1, LL &b1, LL &a2, LL &b2) { LL fen
阅读全文
摘要:采用暴力枚举。由于n最大不超过2^31, 大概是 2 * 10^9 由于这个数在12! 到 13 ! 之间,而且又由于不含1,所以最高就只有11位。 然后通过枚举每一种以某因子开头连续的情况是否成立,从大到小枚举。 #include <iostream> using namespace std; i
阅读全文
摘要:运用并查集, 先用两个数组,分别存连通的两个点,然后判断是否这两个点至少有一个被攻占,如果没有就合并。最后查一下是否全是孤立的点。 #include <iostream> #include <cstring> using namespace std; const int N = 10010; int
阅读全文
摘要:但是第二步求x的编号需要0(n) 的 时间复杂度。 需要进行优化; 压缩路径: 就是运用递归的方法,在找x的祖宗节点的时候,顺便把这一路上的父节点都连到祖宗节点上,那么下一次查询祖宗节点的时候只需0(1)的时间复杂度就可以了。 int find(int x) { if(f[x] != x) f[x]
阅读全文
摘要:要学会建堆,然后知道用数组模拟堆的优点。 #include <iostream> #include <cstring> #include <map> using namespace std; const int N = 1010; int heap[N]; int n, m; void insert
阅读全文
摘要:训练的时候写不出来这道题,(其实我看到字符串的题就头大) 不过看完题解感觉还好。 分析一下: 我们从起点开始出发,但是要分两种情况。 回文显然存在两种情况:一种是像 abcdcba ,这样的中间一个对称轴的回文另一种则是abccbd ,这样的中间对称轴为空气的回文 所以我们在走的过程中。分别向两边扩
阅读全文
摘要:虽然这道题在比赛的时候,惊险的AC了,但是我之前做过的,比赛遇到了还是有点慌,就记录一下。希望以后心态好一点。 可以先假设中间会输出两个一点,然后推导公式 sum = i * i, 但是最后要减去1,而 i--, 这样i就是对应的层数了(对了,要记得乘2,因为sum算的是一个完整的,而我们假设的是两
阅读全文