
Pat甲级
听说Pat甲级数据结构题目不错,我也来看看。。。
徐伯莱
Stay Hungry, Stay Foolish.
展开
-
2020 PAT 甲级冬季题解
第一题#include<iostream>using namespace std;int n;int a = 0, b = 1, c;int main() { scanf("%d", &n); while(true) { if(a <= n && b >= n) { printf("%d\n", (n - a) <= (b - n) ? a : b); break; } c = b; b += a; a =原创 2021-03-02 13:56:33 · 431 阅读 · 0 评论 -
2020 PAT 甲级秋季题解
第一题#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;const int N = 10010;const int INF = 0x3f3f3f3f;int n;vector<int> milk, w;int main() { scanf("%d", &n); milk.resize(n +原创 2021-03-03 14:30:46 · 542 阅读 · 3 评论 -
2020 PAT 甲级春季题解
第一题#include<iostream>#include<string>#include<algorithm>#include<cstdio>using namespace std;bool isPrime(int x) { if(x < 2) return false; for(int i = 2; i <= sqrt(x); ++i) if(x % i == 0) return false; return true; }原创 2021-03-02 17:04:37 · 252 阅读 · 0 评论 -
Pat甲级题解
初衷虽然网上有很多Pat甲级题解,但是本题解纯属为了记录一下自己刷题遇到的困难和解题思路,也为2019春季的甲级考试做准备。欢迎同考甲级的童靴一起交流。建议相信很多刷Pat甲级的都是新人,要么是acmer刚刚入坑者,要么是刚刚接触这种OJ在线评测。想想当初我入坑的时候,每次提交都会抱很多莫名其妙的错误,其中甚至一道题因为一个测试点几天都过不了。当然找题解是解决问题...原创 2019-01-20 16:53:17 · 2347 阅读 · 0 评论 -
Pat甲级必备常规算法
本博文旨在记录刷Pat中时遇到的常规算法,也算是对自己学习算法的一次总结。目标是用最简单的代码诠释算法。因博主水平有限,如有不足,尽请留言,谢谢。 二分查找树的遍历 manacher算法 ...原创 2019-01-25 14:35:42 · 1283 阅读 · 0 评论 -
1147 Heaps (30 point(s))
题解堆的判定。#include<cstdio>using namespace std;const int MAXN = 1e3 + 10;int n, m;int t[MAXN];void getpost(int root) { if(root > n) return; getpost(root<<1); getpost(root<&l...原创 2019-02-20 18:32:39 · 433 阅读 · 2 评论 -
1146 Topological Order (25 point(s))
题解拓扑排序。#include<iostream>#include<cstring>#include<vector>using namespace std;const int MAXN = 1e3 + 10;vector<int> e[MAXN];int in[MAXN], t[MAXN];int n, m, a, b, ...原创 2019-02-20 17:57:09 · 223 阅读 · 0 评论 -
1145 Hashing - Average Search Time (25 point(s))
题解解决冲突应该msize / 2就可以了。没有必要msize。 #include<iostream>#include<cstdio>#include<vector>#include<cmath>using namespace std;bool isPrime(int x) { if(x < 2) return fal...原创 2019-02-20 17:38:24 · 249 阅读 · 0 评论 -
1144 The Missing Number (20 point(s))
#include<cstdio>#include<iostream>#include<unordered_map>using namespace std;unordered_map<int, bool> have;int n, x;int main() { scanf("%d", &n); for(int i = 0; ...原创 2019-02-19 12:23:02 · 225 阅读 · 0 评论 -
1143 Lowest Common Ancestor (30 point(s))
题解利用BST的性质即可。#include<iostream>#include<cstdio>#include<vector>#include<unordered_map>using namespace std;int w, u, v, n, m;unordered_map<int, bool> have;in...原创 2019-02-18 18:54:06 · 273 阅读 · 0 评论 -
1142 Maximal Clique (25 point(s))
题解最大点集判断。 #include<iostream>#include<cstdio>#include<cstring>using namespace std;const int MAXN = 210;int e[MAXN][MAXN];int nv, ne, m, k, a, b;int have[MAXN], v[MAXN];...原创 2019-02-18 18:51:56 · 200 阅读 · 0 评论 -
1141 PAT Ranking of Institutions (25 point(s))
题解unordered_map #include<iostream>#include<cstdio>#include<unordered_map>#include<algorithm>#include<vector>using namespace std;struct node { string school; ...原创 2019-02-18 18:49:58 · 246 阅读 · 0 评论 -
1140 Look-and-say Sequence (20 point(s))
#include<iostream>#include<cstdio>#include<string>using namespace std;string res;int n;int main() { cin >> res >> n; for(int i = 0; i < n - 1; ++i) { char...原创 2019-02-18 18:45:56 · 222 阅读 · 0 评论 -
1139 First Contact (30 point(s))
题解技巧性在于交际网络中,只录入同性关系。#include<iostream>#include<cstdio>#include<map>#include<algorithm>#include<vector>using namespace std;const int MAXN = 1e4;struct node ...原创 2019-02-17 17:42:59 · 342 阅读 · 0 评论 -
1138 Postorder Traversal (25 point(s))
题解树的遍历。#include<cstdio>#include<iostream>#include<vector>using namespace std;vector<int> pre, in, post;void getpost(int l, int r, int root) { if(l > r) return;...原创 2019-02-17 17:09:18 · 274 阅读 · 0 评论 -
1137 Final Grading (25 point(s))
题解STL应用。#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<map>using namespace std;const int MAXN = 1e4 + 10;struct node { string...原创 2019-02-17 17:07:37 · 209 阅读 · 0 评论 -
1136 A Delayed Palindrome (20 point(s))
题解回文串简单判断。#include<iostream>#include<string>#include<cstdio>#include<algorithm>using namespace std;bool isPalin(string a) { string b = a; reverse(a.begin(), a.end(...原创 2019-02-17 13:01:09 · 364 阅读 · 0 评论 -
1135 Is It A Red-Black Tree (30 point(s))
题解红黑树性质的判断。#include<iostream>#include<cstdio>#include<vector>#include<algorithm>using namespace std;vector<int> pre;int n, k;struct node { node *l, *r; int ...原创 2019-02-17 12:56:00 · 332 阅读 · 0 评论 -
1134 Vertex Cover (25 point(s))
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;int n, m, k, a, b, nv;vector<vector<int>> e;int main() { scanf("...原创 2019-02-16 18:36:21 · 217 阅读 · 0 评论 -
1133 Splitting A Linked List (25 point(s))
#include<iostream>#include<cstdio>#include<vector>using namespace std;const int MAXN = 1e5;struct node { int data, nex;}t[MAXN]; vector<int> res[3];int n, k, x, fir...原创 2019-02-16 18:35:14 · 222 阅读 · 0 评论 -
1132 Cut Integer (20 point(s))
#include<cstdio>#include<iostream> #include<string>#include<algorithm>using namespace std; typedef long long ll;ll n, a, b, c;string s;int main() { scanf("%lld", &a...原创 2019-02-16 18:34:05 · 221 阅读 · 0 评论 -
1131 Subway Map (30 point(s))
题解spfa可以解,但是比较麻烦。最好还是暴力dfs.以下题解少考虑了情况,Pat给的测试数据还是太少了,所以过了。#include<iostream>#include<cstdio>#include<vector>#include<algorithm>#include<queue>using namespac...原创 2019-02-16 21:39:09 · 387 阅读 · 0 评论 -
1130 Infix Expression (25 point(s))
题解树的遍历,输出树的中序序列。#include<iostream>#include<cstdio>#include<string>#include<algorithm>#include<vector> using namespace std;const int MAXN = 22;int root, n; ...原创 2019-02-16 13:17:16 · 207 阅读 · 0 评论 -
1129 Recommendation System (25 point(s))
题解set中erase函数的使用。#include<iostream>#include<set>#include<cstdio>using namespace std;const int MAXN = 5e4 + 10;struct node { int item, cnt; bool operator < (const nod...原创 2019-02-16 13:10:17 · 216 阅读 · 0 评论 -
1128 N Queens Puzzle (20 point(s))
题解八皇后问题。#include<iostream>#include<cstdio>using namespace std;const int MAXN = 1e3 + 10;int a[MAXN];int k, n;int main() { scanf("%d", &k); for(int i = 0; i < k; ++i) ...原创 2019-02-16 12:36:03 · 207 阅读 · 0 评论 -
1127 ZigZagging on a Tree (30 point(s))
题解树的遍历变形。#include<iostream>#include<cstdio>#include<vector>using namespace std;int n;vector<int> in, post;vector<vector<int>> level;void getlevel(int ...原创 2019-02-15 18:06:55 · 226 阅读 · 1 评论 -
1126 Eulerian Path (25 point(s))
#include<iostream>#include<cstdio>#include<queue>#include<vector>using namespace std;const int MAXN = 510;bool vis[MAXN];vector<vector<int>> e; int n, ev...原创 2019-02-15 19:12:24 · 205 阅读 · 0 评论 -
1125 Chain the Ropes (25 point(s))
#include<cstdio>#include<iostream>#include<vector>#include<algorithm>using namespace std;vector<int> t;int n, res;int main() { scanf("%d", &n); t.resize(n)..原创 2019-02-15 18:05:21 · 214 阅读 · 1 评论 -
1124 Raffle for Weibo Followers (20 point(s))
#include<iostream>#include<cstdio>#include<string>#include<map>using namespace std;int m, n, s, flag;string name;map<string, bool> have;int main() { scanf("%d...原创 2019-02-15 18:04:11 · 255 阅读 · 1 评论 -
1123 Is It a Complete AVL Tree (30 point(s))
题解完全AVL树。考察AVL树的建树与完全性判断。 #include<cstdio>#include<iostream>#include<algorithm>#include<queue>using namespace std;struct node { node *l, *r; int v;};node* rot...原创 2019-02-15 16:17:39 · 219 阅读 · 1 评论 -
1122 Hamiltonian Cycle (25 point(s))
题解哈密顿回路。由指定的起点前往指定的终点,途中经过所有其他节点且只经过一次。在图论中是指含有哈密顿回路的图,闭合的哈密顿路径称作哈密顿回路,含有图中所有顶点的路径称作哈密顿路径。判断给出方案的连通性与环路判断。#include<cstdio>#include<iostream>#include<vector>using namespac...原创 2019-02-15 16:20:01 · 215 阅读 · 0 评论 -
1121 Damn Single (25 point(s))
#include<iostream>#include<set>#include<vector>using namespace std;int main(){ int n, a, b, m; scanf("%d", &n); vector<int> couple(100000, -1); for(int i = 0; i ...原创 2019-02-15 10:25:03 · 204 阅读 · 0 评论 -
1120 Friend Numbers (20 point(s))
题解模拟题。#include<iostream>#include<cstdio>#include<set>using namespace std;set<int> res;int getsum(int x) { int ret = 0; while(x) ret += x % 10, x /= 10; return r...原创 2019-02-15 10:22:54 · 199 阅读 · 0 评论 -
1119 Pre- and Post-order Traversals (30 point(s))
题解怎么确定是否有唯一的树, 其实就是看除了叶子以外的每个节点是否都有两个儿子, 因为有一个儿子的话,它既可以是左儿子也可以是右儿子。当不唯一时,全部当右儿子看待。#include<iostream>#include<cstdio>#include<vector>using namespace std;vector<int>...原创 2019-02-12 18:24:41 · 308 阅读 · 0 评论 -
1118 Birds in Forest (25 point(s))
题解并查集。#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int MAXN = 1e4 + 10;int father[MAXN], book[MAXN], cnt[MAXN];int find(int x) { retur...原创 2019-02-12 17:40:59 · 217 阅读 · 0 评论 -
1117 Eddington Number (25 point(s))
题解题意比较难理解。假设骑车E天,则这E天内每天所骑行距离必须大于E。(E是动态变化的)#include<iostream>#include<cstdio>#include<vector>#include<algorithm>using namespace std;int n;int main() { scanf("%...原创 2019-02-12 17:39:16 · 249 阅读 · 0 评论 -
1116 Come on! Let's C (20 point(s))
#include<iostream>#include<map>#include<cstdio>#include<cmath>using namespace std;const int MAXN = 1e5;int ran[MAXN];map<int, bool> have;int n, k, x;bool ispr...原创 2019-02-12 17:35:59 · 174 阅读 · 0 评论 -
1115 Counting Nodes in a BST (30 point(s))
题解BST建树。#include<iostream>#include<cstdio>using namespace std;const int MAXN = 1e3 + 10;int level[MAXN];int maxdepth, n;struct node { node *l, *r; int v;}; node* build(int...原创 2019-02-11 18:03:25 · 205 阅读 · 0 评论 -
1114 Family Property (25 point(s))
题解模拟题。#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int MAXN = 1e5;struct node { int id, fat, mot, num, people; int child[8]; double a...原创 2019-02-11 17:48:22 · 256 阅读 · 0 评论 -
1113 Integer Set Partition (25 point(s))
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;int n, sum, half;int main() { scanf("%d", &n); vector<int> res(n);..原创 2019-02-11 11:18:24 · 222 阅读 · 0 评论