
复试上机
Handsomk
为了理解递归,我们首先需要理解递归
展开
-
洛谷--P1347 排序
题目链接每加入一个条件就要进行一次拓扑排序有以下三种情况:条件不足:多个入度为0、多个出度为0、当前能得出的序列长度小于总字母数量出现环路成功判断测试点14 6C<DC<BB<AC<DD<AA<AInconsistency found after 6 relations.#include <iostream>#include <queue>#include <vector>#includ原创 2022-03-18 21:59:16 · 539 阅读 · 0 评论 -
浙大上机题--最短路径问题
题目链接堆优化迪杰斯特拉#include <iostream>#include <queue>#include <vector>#include <cstring>using namespace std;typedef pair<int, int> pii;const int N = 1010;struct node { int to, d, m;};vector<vector<node>>原创 2022-03-18 20:20:02 · 286 阅读 · 0 评论 -
浙大上机题--继续畅通工程
题目链接要先计算连通分支的个数,最终只有一个连通分支即可#include <iostream>#include <algorithm>using namespace std;const int N = 5010;struct node { int wei, x, y, sta; bool operator < (const node& t) const { return wei < t.wei; }}e[原创 2022-03-18 18:23:09 · 276 阅读 · 0 评论 -
浙大上机题--还是畅通工程
题目链接最小生成树模板题#include <iostream>#include <algorithm>using namespace std;const int N = 5010;struct node { int wei, x, y; bool operator < (const node& t) const { return wei < t.wei; }}e[N];int f[110];int原创 2022-03-18 18:07:36 · 257 阅读 · 0 评论 -
浙大上机题--畅通工程
简单的并查集,主要复习模板题目链接#include <iostream>using namespace std;const int N = 1010;int f[N];int find(int x) { if (x != f[x]) return f[x] = find(f[x]); return f[x];}void merge(int a, int b) { int ta = find(a); int tb = find(b); .原创 2022-03-17 21:36:26 · 439 阅读 · 0 评论 -
华科上机题--二叉排序树
题目链接#include <iostream>using namespace std;struct node { int val; node *l, *r; node(int x) : val(x), l(nullptr), r(nullptr) {}};int insertTree(node *&root, int x) { if (root == nullptr) { root = new node(x);原创 2022-03-14 20:37:45 · 481 阅读 · 0 评论 -
华科上机题--二叉树遍历
题目链接#include <iostream>using namespace std;struct node { char c; node *l, *r; node(char x ) : c(x), l(nullptr), r(nullptr) {}};node* buildTree(string pre, string mid, int pl, int pr, int ml, int mr) { if (pl > pr) {原创 2022-03-14 20:19:49 · 1480 阅读 · 0 评论 -
清华大学上机题-二叉树遍历
题目链接#include <iostream>#include <vector>using namespace std;struct node { char c; node *l; node *r; node(char x) : c(x), l(nullptr), r(nullptr) {}};node* buildTree(int &pos, string str) { if (pos >= str.size()原创 2022-03-14 19:52:05 · 2113 阅读 · 0 评论 -
DFS-A Knight‘s Journey
题目链接关键点:注意输出时的字母要按字典序,具体就是深搜时的方向排序问题#include <iostream>#include <queue>#include <algorithm>#include <cstring>#include <vector>using namespace std;struct node { int x, y; node(int a, int b) : x(a), y(b){};}原创 2022-03-12 23:04:44 · 219 阅读 · 0 评论 -
清华大学上机题--玛雅人的密码
清华上机题链接#include <iostream>#include <string>#include <queue>#include <unordered_map>using namespace std;struct node { string s; int cnt; node(string x, int y) : s(x), cnt(y) {};};unordered_map<string, bool>原创 2022-03-12 21:57:46 · 204 阅读 · 0 评论 -
Catch That Cow--宽度优先搜索
题目链接#include <iostream>#include <climits>#include <queue>using namespace std;const int N = 100010;struct node { int pos, t; node(int x, int y) : pos(x), t(y){}};int ans;bool flag[N];queue<node> q;void bfs(int cu原创 2022-03-12 20:12:52 · 366 阅读 · 0 评论 -
今年暑假不AC
时隔一年半重写,区间贪心按右端点排序题目链接#include <iostream>#include <vector>#include <algorithm>using namespace std;struct node { int st, ed; bool operator < (const node &t) const { if (ed != t.ed) return ed < t.ed; .原创 2022-03-09 20:52:45 · 62 阅读 · 0 评论 -
矩阵快速幂
题目-矩阵幂模板#include <iostream>#include <algorithm>#include <string>#include <cstring>using namespace std;const int N = 15;struct Matrix { int v[N][N]; int row, col;};Matrix mutil(Matrix a, Matrix b) { Matrix c;原创 2022-03-08 22:48:59 · 117 阅读 · 0 评论 -
求约数个数
约数的个数约数定理#include <iostream>using namespace std;const int N = 1e5 + 10;int primes[N];bool st[N];int cnt = 0;void getPrimes() { for (int i = 2; i < N; i++) { if (!st[i]) primes[++cnt] = i; for (int j = 1; i * prime原创 2022-03-07 19:54:54 · 124 阅读 · 0 评论 -
欧拉筛--质因数的个数
关键点: 每个合数只被最小的质因数筛掉int primes[N];bool st[N];int cnt = 0;void getPrimes() { for (int i = 2; i < N; i++) { if (!st[i]) primes[++cnt] = i; for (int j = 1; i * primes[j] < N; j++) { //i的质因数肯定比primes[j]大,所以就保证了primes.原创 2022-03-07 15:14:53 · 433 阅读 · 0 评论 -
清华大学上机题--10进制 VS 2进制
10进制 VS 2进制一系列高精度操作#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;//高精度除以低精度(2)void div(string &s) { string ans = ""; int r = 0; for (int i = 0; i < s.leng原创 2022-03-06 12:32:28 · 180 阅读 · 0 评论 -
清华大学上机题--进制转换
进制转换清华大学上机题十进制转二进制,十进制最多有30位主要用高精度除以低精度#include <iostream>#include <vector>#include <algorithm>using namespace std;void div(vector<int> &v) { vector<int> c; int r = 0; for (int i = 0; i < v.size(原创 2022-03-05 22:05:23 · 239 阅读 · 0 评论 -
KMP-字符串匹配
KMP算法原创 2022-02-25 14:15:19 · 232 阅读 · 0 评论