![](https://img-blog.csdnimg.cn/20210201183057828.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224)
PAT专栏
备战PAT甲级,内附近几年真题
Raymond&yin
Learn to Code.
展开
-
2020PAT甲级冬季满分题解
刚刚考完满分,hhhhA The Closest Fibonacci Number 热身题,斐波那契数。#include<iostream>#include<vector>using namespace std;vector<int> nums;void get() { int tmp; for (int i = 2;; i++) { tmp = nums[i - 2] + nums[i - 1]; if原创 2020-12-05 15:40:04 · 3173 阅读 · 6 评论 -
PAT甲级2020春季真题题解
题目下载以及满分代码A.Prime Day 签到题,可以使用stoi将字符串转换为数字,然后试除法判断是否为素数。#include<iostream>#include<string>using namespace std;bool check(const string &s) { int a = stoi(s); //0 1不是素数 if (a <= 1) return false; for (int原创 2020-12-01 21:19:02 · 351 阅读 · 0 评论 -
PAT甲级2019冬季真题题解
题目及源代码下载:PAT甲级2019冬真题及题解A Good in C 字符串题,开一个三维数组char型,第一维大小为26,为26个字母,后面两维是存放表示该字母的7*5字符。后面使用getline读入一行,按照单词输出,注意细节,比如最后不能有多余的空行等等。#include<cstdio>#include<iostream>#include<string>using namespace std;char arr[26][7][6];string原创 2020-11-30 22:39:28 · 297 阅读 · 0 评论 -
PAT甲级2019秋季真题题解
题目及AC代码下载A Foreover 热身题,结合求最大公约数、检查是否为素数、DFS回溯,很综合的一道题目,注意剪枝,否则数据过大可能会TLE。#include<iostream>#include<string>#include<vector>#include<algorithm>#define ac cin.tie(0);cin.sync_with_stdio(0);using namespace std;string s;//n原创 2020-12-02 22:43:59 · 1283 阅读 · 7 评论 -
PAT甲级2019春季真题题解
PAT甲级2019春季题目及满分代码下载A Sexy Primes 签到题,素数不需要用筛法,直接O(sqrt(n))即可。#include<iostream>using namespace std;bool check(int a) { if (a < 2) return false; for (int i = 2; i * i <= a; i++) if (a % i == 0) retur原创 2020-12-03 23:06:46 · 306 阅读 · 0 评论 -
PAT甲级2018冬季真题题解
A Google Recruitment 热身题,素数,stoll函数,注意数据范围。#include<iostream>#include<string>using namespace std;bool check(const string &s) { long long tmp = stoll(s); if (tmp < 2) return false; for (int i = 2; (long long) i原创 2020-12-04 19:57:18 · 244 阅读 · 0 评论 -
PAT甲级2018冬秋季真题题解
A Werewolf - Simple Version 简单的枚举题。#include<iostream>#define ac cin.sync_with_stdio(0);using namespace std;const int MAXN = 110;int arr[MAXN];int n;bool check(int a, int b) { int cnt = 0, wcnt = 0; for (int i = 1; i <= n; i++)原创 2020-12-04 23:09:00 · 238 阅读 · 0 评论 -
PAT甲级官网 刷题(7)
PAT1056 Mice and Rice 细心再细心,理解题意,模拟。#include<iostream>#include<vector>#include<algorithm>#define ac cin.tie(0);cin.sync_with_stdio(0);using namespace std;const int MAXN = 1010;int arr[MAXN], ans[MAXN], cnt[MAXN];int n, m;int原创 2020-11-29 23:00:52 · 191 阅读 · 0 评论 -
PAT甲级官网 刷题(5)
PAT1129 Recommendation System 需要稍加思考,每次都sort会TLE。#include<iostream>#include<algorithm>#define ac cin.tie(0);cin.sync_with_stdio(0);using namespace std;const int MAXN = 50010;int arr[20], cnt[MAXN];//按照次数排序,若相同则按照大小排序bool cmp(int a,原创 2020-11-26 23:24:44 · 228 阅读 · 0 评论 -
PAT甲级官网 刷题(4)
PAT1114 Family Property 并查集,麻烦的是需要把人的编号映射到0-n,同时还需要把0-n逆映射到原来的编号。#include<iostream>#include<vector>#include<algorithm>#include<cmath>using namespace std;const int MAXN = 10010;const double eps = 1e-6;//1.2.3映射到原来多的数字int原创 2020-11-25 23:51:59 · 234 阅读 · 0 评论 -
PAT甲级官网 刷题(3)
PAT1130 Infix Expression 递归,但是官网有个测试点没过,不知道错在哪里,欢迎指出#include<iostream>#define ac cin.tie(0);cin.sync_with_stdio(0);using namespace std;const int MAXN = 30;int le[MAXN], ri[MAXN];string val[MAXN], ans;bool vis[MAXN];int n;void dfs(int ro原创 2020-11-24 23:20:58 · 215 阅读 · 0 评论 -
PAT甲级官网 刷题(2)
PAT1154 Vertex Coloring 数据量过大,但是边数不是很多,稀疏图,开邻接表存储边,注意使用set来记录使用的颜色数,PAT题目严格意义上涉及算法也不是很多。#include<iostream>#include<vector>#include<unordered_set>#define ac cin.tie(0);cin.sync_with_stdio(0);using namespace std;const int MAXN = 10原创 2020-11-23 23:15:58 · 331 阅读 · 0 评论 -
PAT甲级官网 刷题(1)
PAT1138 Postorder Traversal 根据前序和中序遍历确定二叉树,模板题,要求输出第一个后序遍历的节点。TIPS:利用map来映射后序遍历在中序遍历中的位置,否则复杂度过高导致TLE。#include<iostream>#include<unordered_map>#define ac cin.tie(0);cin.sync_with_stdio(0);using namespace std;const int MAXN = 50010;int原创 2020-11-22 23:23:46 · 1041 阅读 · 0 评论