
PAT甲级
学编程的蒟蒻
追求简短、逻辑清晰的代码
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
1155 Heap Paths (30 分)
1155 Heap Paths (30 分)#include <iostream>#include <vector>using namespace std;vector<int> v;int a[1010], n, maxn = 1, minn = 1;void dfs(int u) { if(u > n) return; v.push_back(a[u]); dfs(u * 2 + 1); dfs(u * 2); for(int i = 1;原创 2022-02-23 22:53:32 · 104 阅读 · 0 评论 -
1151 LCA in a Binary Tree (30 分)
1151 LCA in a Binary Tree (30 分)#include <iostream>#include <map>using namespace std;map<int, int> m;int pre[10010], in[10010], n, M, x, y;void dfs(int root, int l1, int l2) { if(l1 > l2) return; int proot = m[pre[root]], px =原创 2022-02-23 22:52:58 · 107 阅读 · 0 评论 -
1147 Heaps (30 分)
1147 Heaps (30 分)#include <iostream>using namespace std;int a[2010], post[1010], ret, n, m, maxn, minn;void dfs(int u) { if(u > n) return; dfs(u * 2); dfs(u * 2 + 1); post[ret++] = a[u];}int main() { cin >> m >> n; while(m-原创 2022-02-23 22:52:20 · 97 阅读 · 0 评论 -
1143 Lowest Common Ancestor (30 分)
1143 Lowest Common Ancestor (30 分)#include <iostream>#include <map>using namespace std;map<int,int> m;int a[10100];int main() { int n, M, x, y, t; cin >> M >> n; for(int i = 0; i < n; ++i){ cin >> a[i]; m原创 2022-02-23 22:51:49 · 111 阅读 · 0 评论 -
1139 First Contact (30 分)
1139 First Contact (30 分)思路有空更新#include <iostream>#include <algorithm>#include <vector>#include <map>using namespace std;struct node{ int x, y;};vector<int> v[10000];map<int, map<int, int>> m;bool cmp(n原创 2022-02-23 22:51:18 · 163 阅读 · 0 评论 -
1135 Is It A Red-Black Tree (30 分)
1135 Is It A Red-Black Tree (30 分)#include <iostream>using namespace std;struct node{ int val; struct node *left, *right;};int a[50], n, k; node *build(node *root, int v) { if(root == NULL){ root = new node(); root->val = v; root-&g原创 2022-02-23 22:50:45 · 106 阅读 · 0 评论 -
1127 ZigZagging on a Tree (30 分)
1127 ZigZagging on a Tree (30 分)思路有空更新#include <iostream>#include <queue>#include <vector>using namespace std;struct node{ int l, r, h;}a[10050];vector<int> v[40];int in[40], post[40], maxh;int dfs(int l, int l1, int l2,原创 2022-02-23 22:49:00 · 109 阅读 · 0 评论 -
1123 Is It a Complete AVL Tree (30 分)
1123 Is It a Complete AVL Tree (30 分)模板题#include <iostream>using namespace std;int tree[500];struct node{ int val; struct node *left, *right;};node *rotateLeft(node *root) { node *t = root->right; root->right = t->left; t->lef原创 2022-02-23 22:48:15 · 132 阅读 · 0 评论 -
1119 Pre- and Post-order Traversals (30 分)
1119 Pre- and Post-order Traversals (30 分)思路有空更新#include <iostream>using namespace std;int pre[40], post[40], in[40], ret, f;void dfs(int l1, int l2, int l3, int l4) { if(l1 > l2) return; if(l1 == l2){ in[ret++] = pre[l1]; return; } i原创 2022-02-23 22:47:38 · 94 阅读 · 0 评论 -
1115 Counting Nodes in a BST (30 分)
1115 Counting Nodes in a BST (30 分)思路有空更新#include <iostream>using namespace std;int level[1100], maxh;struct node{ int value; struct node *left, *right;};node* build(node *root, int x) { if(root == NULL) { root = new node(); root->va原创 2022-02-23 22:45:35 · 93 阅读 · 0 评论 -
1111 Online Map (30 分)
1111 Online Map (30 分)思路有空更新#include <iostream>#include <cstring>#include <vector> using namespace std;const int inf = 0x3f3f3f3f;vector<int> p1, p2;int map1[550][550], map2[550][550], vis[550], dis[550], fast[550], cnt[550]原创 2022-01-29 21:02:04 · 194 阅读 · 0 评论 -
1107 Social Clusters (30 分)
1107 Social Clusters (30 分)思路有空更新#include <iostream>#include <set>#include <algorithm>using namespace std;int fa[2500], ret[2500];set<int> s;int find(int x) { if(fa[x] == x) return x; else return fa[x] = find(fa[x]);}int原创 2022-01-29 21:01:00 · 90 阅读 · 0 评论 -
1103 Integer Factorization (30 分)
1103 Integer Factorization (30 分)思路有空更新#include <iostream>#include <cmath>#include <vector> using namespace std;int a[25], N, n, k, p, maxf;vector<int> b(450), ans(450);void dfs(int x, int len, int sumf, int sum) { if(len &原创 2022-01-29 20:59:30 · 219 阅读 · 0 评论 -
1099 Build A Binary Search Tree (30 分)
1099 Build A Binary Search Tree (30 分)思路有空更新#include <iostream>#include <algorithm>#include <queue> using namespace std;struct node{ int l, r, value;}a[200];int b[200], ret;void dfs(int x) { if(a[x].l != -1) dfs(a[x].l); a[x].原创 2022-01-29 20:58:53 · 288 阅读 · 0 评论 -
1095 Cars on Campus (30 分)
1095 Cars on Campus (30 分)思路有空更新#include <iostream>#include <vector>#include <map>#include <algorithm>using namespace std;struct node{ string id; int time, flag;}a[10010]; vector<node> v;map<string, int> m;原创 2022-01-29 20:46:07 · 186 阅读 · 0 评论 -
1091 Acute Stroke (30 分)
1091 Acute Stroke (30 分)思路有空更新#include <iostream>#include <queue>using namespace std;int dir[6][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {-1, 0, 0}, {0, -1, 0}, {0, 0, -1}};struct node{ int x, y, z;};int a[1300][130][70], vis[1300][130][原创 2022-01-29 20:45:23 · 240 阅读 · 0 评论 -
1087 All Roads Lead to Rome (30 分)
1087 All Roads Lead to Rome (30 分)思路有空更新#include <iostream>#include <cstring>#include <map>using namespace std;const int inf = 0x3f3f3f3f;int e[250][250], vis[250], dis[250], path[250], ret[250], cnt[250], a[250], aa[250];double a原创 2022-01-29 20:44:47 · 564 阅读 · 0 评论 -
1080 Graduate Admission (30 分)
1080 Graduate Admission (30 分)思路有空更新#include <iostream>#include <vector>#include <algorithm>using namespace std;struct node{ int id, ge, gi, r, admit; double avg; int ch[10];}a[40050];int b[150];vector<int> v[150]; bool原创 2022-01-29 20:43:41 · 208 阅读 · 0 评论 -
1076 Forwards on Weibo (30 分)
1076 Forwards on Weibo (30 分)思路有空更新#include <iostream>#include <cstring>#include <vector>#include <queue>using namespace std;vector<int> v[1050];int n, l, k, x, m, vis[1050];int bfs(int x){ int level = 0, ret = 0; q原创 2022-01-29 20:42:59 · 93 阅读 · 0 评论 -
1072 Gas Station (30 分)
1072 Gas Station (30 分)#include <iostream>#include <cstring>using namespace std;const int inf = 0x3f3f3f3f;int map[1050][1050], vis[1050], dis[1050];int n, m, k, ds;void dijkstra(int s){ memset(vis, 0, sizeof vis); memset(dis, inf, siz原创 2022-01-29 20:42:11 · 158 阅读 · 0 评论 -
1068 Find More Coins (30 分)
1068 Find More Coins (30 分)#include <iostream>#include <vector>#include <algorithm>using namespace std;const int inf = 0x3f3f3f3f;vector<int> ans;int dp[10010], v[10010], vis[10010][110]; int main() { int n, m; cin >>原创 2022-01-27 23:54:37 · 114 阅读 · 0 评论 -
1064 Complete Binary Search Tree (30 分)
1064 Complete Binary Search Tree (30 分)#include <iostream>#include <algorithm> using namespace std;int a[1050], tree[1050], n, ret;void dfs(int root){ if(root > n) return; dfs(root * 2); tree[root] = a[ret++]; dfs(root * 2 + 1);}原创 2022-01-27 23:51:17 · 353 阅读 · 0 评论 -
1057 Stack (30 分)
1057 Stack (30 分)#include <iostream>#include <stack>using namespace std;const int N = 1e5 + 10;int a[N];stack<int> s;int lowbit(int x){ return x & -x;}void add(int x, int y){ for(int i = x; i < N; i += lowbit(i)) a[i]原创 2022-01-27 23:47:33 · 94 阅读 · 0 评论 -
1053 Path of Equal Weight (30 分)
1053 Path of Equal Weight (30 分)思路有空更新#include <iostream>#include <algorithm>#include <vector>using namespace std;vector<int> v[1010], path[1010];int weight[1010], a[1010];int n, m, s, ret;void dfs(int x, int h, int sum) {原创 2022-01-27 23:40:51 · 104 阅读 · 0 评论 -
1049 Counting Ones (30 分)
1049 Counting Ones (30 分)思路有空更新#include <iostream>using namespace std;int main(){ int n, wei = 1, now, left, right, ans = 0; cin >> n; while(n / wei){ now = n / wei % 10; //此时位上数字 left = n / (wei * 10); //左边数字 right = n % wei;原创 2022-01-27 23:38:24 · 185 阅读 · 0 评论 -
1045 Favorite Color Stripe (30 分)
1045 Favorite Color Stripe (30 分)思路有空更新#include <iostream>using namespace std;int a[10010], vis[10010], dp[10010];int main() { int n, m, l, x, ret = 0; cin >> n >> m; for(int i = 1; i <= m; ++i){ cin >> x; vis[x] = i;原创 2022-01-27 23:37:49 · 191 阅读 · 0 评论 -
1038 Recover the Smallest Number (30 分)
1038 Recover the Smallest Number (30 分)思路有空更新#include <iostream>#include <algorithm>#include <vector>using namespace std;bool cmp(string a, string b){ return a + b < b + a;}int main() { int n; cin >> n; vector<stri原创 2022-01-27 23:37:13 · 70 阅读 · 0 评论 -
1034 Head of a Gang (30 分)
1034 Head of a Gang (30 分)思路有空更新#include <iostream>#include <map>using namespace std;map<string, string> fa;map<string, int> weight, ret, sum, ans;string find(string x){ string y = x; while(x != fa[x]) x = fa[x]; if(weight原创 2022-01-27 23:36:35 · 196 阅读 · 0 评论 -
1030 Travel Plan (30 分)
1030 Travel Plan (30 分)思路有空更新#include <iostream>#include <cstring>using namespace std;const int inf = 0x3f3f3f3f;int map[550][550], vis[550], dis[550], path[550];int a[550][550], sum[550];int n, m, S, D;void dijkstra(int s){ memset(di原创 2022-01-27 23:35:44 · 339 阅读 · 0 评论 -
1022 Digital Library (30 分)
1022 Digital Library (30 分)思路有空更新#include <iostream>#include <sstream>#include <algorithm>#include <vector>#include <map>using namespace std;map<string, vector<string> > m;int main() { int n, M, x; strin原创 2022-01-27 23:34:23 · 70 阅读 · 0 评论 -
7-4 Helping the Couriers (30 分)
7-4 Helping the Couriers (30 分)Gao recently took a part time job as a courier(快递员). Every time as he picks up N packages from the distribution center, he would always try to find the best way to deliver those packages so that he can finish this round as q原创 2021-12-23 17:21:03 · 590 阅读 · 0 评论 -
7-3 Size of Military Unit (25 分)
7-3 Size of Military Unit (25 分)记忆化搜索,每次搜存每个点#include <iostream> #include <vector>using namespace std;vector<int> v[100100];int ans[100100];int dfs(int x) { for(int i = 0; i < v[x].size(); ++i) ans[x] += dfs(v[x][i]); return原创 2021-12-23 16:45:42 · 873 阅读 · 0 评论 -
7-2 Rank a Linked List (25 分)
7-2 Rank a Linked List (25 分)找到-1的点,从后往前找就行#include <iostream>#include <map>using namespace std;int a[100100];map<int, int> m;int main() { int n, root, ret = 1, x; cin >> n; for(int i = 0; i < n; ++i) { cin >> x原创 2021-12-23 16:39:43 · 2442 阅读 · 1 评论 -
7-1 Fake News (20 分)
7-1 Fake News (20 分)看懂题目就行,统计每组数据出现次数,按比例标记就行。#include <iostream>#include <map>using namespace std;int a[10010], vis[10010];int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, x; cin >> n >> m; while(m--) {原创 2021-12-23 16:19:28 · 1046 阅读 · 3 评论 -
PAT-2021年冬季考试(满分)
PAT-2021年冬季考试 - Advanced Level贴贴这次满分的代码7-1 Fake News (20 分)#include <iostream>#include <map>using namespace std;int a[10010], vis[10010];int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, x; cin >> n >> m; w原创 2021-12-21 19:32:08 · 779 阅读 · 0 评论 -
pat甲级2021冬季考试(满分)
满分!!!第一次参加pat甲级就满分了很开心哈哈哈,看来这几天刷题没有白费哈哈。当时那个小时%24卡了我一个多小时,差点心态没了,还好被我意识到了哈哈哈原创 2021-12-19 16:38:30 · 1191 阅读 · 3 评论 -
1136 A Delayed Palindrome (20 分)
1136 A Delayed Palindrome (20 分)#include <iostream>#include <algorithm>#include <string>using namespace std;int main(){ int i; string a, b; cin >> a; b = a; reverse(b.begin(),b.end()); if(a == b){ cout << a <<原创 2021-12-14 23:13:34 · 599 阅读 · 0 评论 -
1134 Vertex Cover (25 分)
1134 Vertex Cover (25 分)#include <iostream>#include <cstring>#include <vector>using namespace std;vector<int> v[10010];int vis[10010], s[10010], f;void dfs(int x) { vis[x] = 1; for(int i = 0; i < v[x].size(); ++i){ if(原创 2021-12-14 23:13:02 · 331 阅读 · 0 评论 -
1133 Splitting A Linked List (25 分)
1133 Splitting A Linked List (25 分)#include <iostream>#include <vector>#include <map>using namespace std;map<int,pair<int,int>> m;vector<pair<int,int>> v1, v2;int main(){ int node, n, k, x, y, z; cin >&原创 2021-12-14 23:12:19 · 344 阅读 · 0 评论 -
1132 Cut Integer (20 分)
1132 Cut Integer (20 分)#include <iostream>using namespace std;int main(){ int n; cin >> n; while(n--) { string s; cin >> s; int c = stoi(s), len = s.size() / 2; int a = stoi(s.substr(0, len)), b = stoi(s.substr(len)); if(a原创 2021-12-14 23:11:30 · 489 阅读 · 0 评论