- 博客(9)
- 收藏
- 关注
原创 1018 Public Bike Management (30 分)-Dijkstra+DFS多条最短路径问题
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 5e2 + 5, inf = 1e9; int n,m,cmax,ed,w[maxn],g[maxn][maxn]; int minsent = inf, minback = inf; vecto.
2021-09-10 11:27:39
143
原创 1131 Subway Map (30 分)-堆优化dijkstra、DFS
1.堆优化dijkstra,有三个样例过不了,有时间再看看 #include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn = 1e4 + 5, inf = 1e9; int n, m, k, N=0; int mp[maxn]; vector<int>
2021-09-09 15:13:27
177
原创 1123 Is It a Complete AVL Tree (30 分)-PTA甲级-AVL树模板题
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; const int maxn = 1e2 + 5, inf = 1e9; struct node { int num; node *left = nullptr, *right = nullptr; }; int get_height(node *t) { if (t == nullptr) .
2021-09-07 16:41:47
153
原创 1107 Social Clusters (30 分)-PTA甲级-并查集模板题
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; const int maxn = 1e3 + 5, inf = 1e9; vector<vector<int>> hob(maxn); int root[maxn]; int get_root(int x) { if (x != root[x]) root[x] = g.
2021-09-07 12:23:32
182
原创 1105 Spiral Matrix (25 分)-PTA甲级-DFS填充螺旋矩阵
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; const int maxn = 1e4 + 5, inf = 1e9; int m, n, N, g[maxn][maxn], dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 }; int r[maxn],vis[maxn][maxn]; void DFS(int x.
2021-09-07 11:46:24
126
原创 1099 Build A Binary Search Tree (30 分)-PTA甲级-BST建树
本题与1064一模一样的思路,建树时统计当前节点左子树的节点数量,以此确定当前节点的num值。 #include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; const int maxn = 1e2+5,inf=1e9; struct node { int num; node *left=nullptr, *right=nullptr; }; int n
2021-09-07 09:38:30
167
原创 1088 Rational Arithmetic (20 分)-PTA甲级-分数四则运算、运算符重载
搞了两个小时才搞出来,就当练习运算符重载了。极其讨厌这种细节一大堆的题,而且还是20分的第一题,希望考场上不要碰到。 坑点: 分母可以为负数 #include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; const int maxn = 205,inf=1e9; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(
2021-09-05 19:00:03
200
原创 1087 All Roads Lead to Rome (30 分)-PTA甲级-Dijkstra点权最短路径条数
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; const int maxn = 205,inf=1e9; string pis[maxn]; unordered_map<string, int> psi; int n, m, st = 0, ed, w[maxn], g[maxn][maxn]; void dijkstra() { .
2021-09-05 16:05:30
138
原创 1064 Complete Binary Search Tree (30 分)-PTA甲级-BST建树
不知道为什么本地运行会卡死,但提交上去可以AC,经过排查问题出在BFS这个函数在本地似乎无法正常返回,有没有大佬帮忙看看。 #include <bits/stdc++.h> #include <unordered_map> using namespace std; const int maxn = 1e3 + 5; #define lowbit(x) ((x)&(-x)) vector<int> v(maxn),ans; int n; struct node
2021-09-03 20:59:14
140
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅