题解
PAT
我成为一只小羊
这个作者很懒,什么都没留下…
展开
-
PAT(甲级)2022 年春季 7-4
这次题好难……我 100 的时候一共才 4 个还是 5 个人。// map 是 n * m 的// x 是救助点// # 不能走// 一条指令是一个数字// 0123 代表 北东南西// 如果目的地不能到达,必须等待下一条指令// 一种贪心算法// 1. 找到 x 的单源最短路径,然后选一个最远的 A ,这个 A 是人可能在的位置// 2. 生成从 A 到 x 的最短路径,如果最短路不唯一,就生成最小的// 3. 计算人目前可能的位置// 4. 如果 x 是人唯一可能在的位置,停止,原创 2022-03-05 16:42:07 · 639 阅读 · 6 评论 -
PAT(甲级)2022 年春季 7-3
// 二叉搜索树// 左子树小于// 右子树大于等于#include <bits/stdc++.h>using namespace std;void in_trav(vector<int> &tree, vector<int> &in_order, int id) { int size = tree.size(); if (id * 2 < size and tree[id * 2] != -1) {原创 2022-03-05 16:40:19 · 280 阅读 · 0 评论 -
PAT(甲级)2022 年春季 7-2
// 找出前 K 个最大的数,并按照降序输出#include <bits/stdc++.h>using namespace std;int main() {#ifdef YD_DEBUG freopen("../in", "r", stdin); freopen("../out", "w", stdout);#endif cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false)原创 2022-03-05 16:39:37 · 349 阅读 · 0 评论 -
PAT(甲级)2022 年春季 7-1
// N 个多选题, 8 个选项 a-h// 获得一个长度为 N 的 string// 得分超过 T 的是// f 开头 -2// a 结尾 -1// 每个最长的相同字母的串的长度大于 5 ,+3// a 后面是 e 或 h -4// 每个最长的连续增长的串的长度大于 3 ,+5// N 问题的个数// T 阈值// K 测试者#include <bits/stdc++.h>using namespace std;int main() {#ifdef YD_原创 2022-03-05 16:38:17 · 241 阅读 · 0 评论 -
PAT 甲级考试终于满分了
竟然有两份证书。申通快递把证书撕坏了好气啊。先留个坑,这应该是个经验贴,等我有时间/心情的时候再说吧。原创 2021-03-20 18:09:59 · 1638 阅读 · 3 评论 -
1005 Spell It Right (20 分)
题意给一个非负整数N,计算N的每一位相加的和,然后输出和的每一位的英文读音。代码#include <iostream>#include <string>using namespace std;int main() { string s; cin >> s; int sum = 0; for (int i = 0;...原创 2019-09-05 17:46:54 · 117 阅读 · 0 评论 -
1004 Counting Leaves (30 分)
知识点: 深度优先搜索题意给出一棵树,计算每一层的叶子节点的个数。代码#include <iostream>#include <vector>using namespace std;vector<int> nodes[105];int leaf[105], level[105], maxLevel;void dfs(int root) {...原创 2019-09-05 17:36:55 · 97 阅读 · 0 评论 -
1003 Emergency (25 分)
知识点: 最短路径题意计算从起点到终点的所有最短路径的个数和这些路径中最大的点权之和。思路因为要统计最短路径的个数,如果使用bellman-ford算法,因为会重复访问节点,所以不能只用一个num数组记录最短路径的个数,还要记录节点的前驱。代码Bellman-Ford#include <cstdio>#include <vector>#include &l...原创 2019-09-05 16:39:11 · 177 阅读 · 0 评论 -
1002 A+B for Polynomials (25 分)
题意计算多项式A+B的和。思路多项式的次数的范围较小,可以使用哈希直接映射。输出时从后往前输出所有系数不为0的指数和系数。代码#include <cstdio>#include <cmath>using namespace std;#define EPS 1e-8#define SIZE 10005double a[SIZE];int main...原创 2019-09-05 15:51:01 · 137 阅读 · 0 评论 -
1001 A+B Format (20 分)
题意计算A+B,输出时每隔三位在数字间加上","。思路从前到后输出每一位,如果当前位满足(i + 1) % 3 == len % 3(i从0开始),那么就应该在这位之后输出一个逗号,排除负号和最后一位的情况。代码#include <iostream>#include <string>using namespace std;int main() { ...原创 2019-09-05 15:44:31 · 110 阅读 · 0 评论 -
7-4 Professional Ability Test (30 分)
#include <algorithm>#include <iostream>#include <queue>#include <unordered_set>#include <vector>using namespace std;struct Node { int T, S; Node() {} Node(int T, int S) : T(T), S(S) {}};bool is_consisten原创 2021-03-15 10:46:02 · 838 阅读 · 0 评论 -
7-3 Left-View of Binary Tree (25 分)
#include <iostream>#include <queue>#include <vector>using namespace std;struct Node { int val, level; Node *left, *right;};Node *rebuild(vector<int> &in, vector<int> &pre, int inL, int preL, int len, i原创 2021-03-15 10:45:09 · 136 阅读 · 0 评论 -
7-2 How Many Ways to Buy a Piece of Land (25 分)
#include <iostream>#include <vector>using namespace std;int main() { int N, M; cin >> N >> M; vector<int> prices(N); for (int i = 0; i < N; i++) { cin >> prices[i]; } int ways =原创 2021-03-15 10:44:22 · 150 阅读 · 0 评论 -
7-1 Panda and PP Milk (20分)
#include <iostream>using namespace std;int w[10005], m[10005];int main() { int n; cin >> n; m[0] = 200; cin >> w[0]; for (int i = 1; i < n; ++i) { cin >> w[i]; // 体重相等 if (w[i]原创 2021-03-15 10:43:09 · 129 阅读 · 0 评论 -
7-4 Chemical Equation (30 分)
#include <algorithm>#include <iostream>#include <map>#include <queue>#include <string>#include <unordered_set>#include <vector>using namespace std;unordered_set<string> reactants;vector<string&g原创 2021-03-14 14:08:00 · 367 阅读 · 0 评论 -
7-3 File Path (25 分)
#include <iostream>#include <string>#include <vector>using namespace std;struct Node { string name; vector<Node*> children; Node* parent;};bool dfs(string& id, Node* file, vector<string>& path) { if (file-原创 2021-03-14 14:07:21 · 156 阅读 · 0 评论 -
7-2 Subsequence in Substring (25 分)
#include <iostream>using namespace std;int main() { string str1, str2; cin >> str1 >> str2; int start = 0, len = str1.length(); for (int i = 0; i < str1.length(); i++) { if (str1[i] == str2[0]) {原创 2021-03-14 14:06:47 · 188 阅读 · 0 评论 -
7-1 The Closest Fibonacci Number (20 分)
#include <iostream>#include <algorithm>#include <vector>using namespace std;vector<int> gen_fb() { vector<int> fb = {0, 1}; for (int i = 2; fb.back() < 1e8; i++) { fb.push_back(fb[i - 1] + fb[i - 2]);原创 2021-03-14 14:06:12 · 133 阅读 · 0 评论 -
7-3 Structure of Max-Heap (25 分)
#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <string>using namespace std;int last = 0;int heap[1005];void insert(int val) { int p = ++last; heap[p] = val; for (; p / 2 >= 1; p /= 2) { if (heap[p] > heap[p / 2]原创 2021-03-13 17:31:56 · 414 阅读 · 0 评论 -
7-2 Lab Access Scheduling (25 分)
#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <algorithm>#include <vector>using namespace std;int timestamp(int h, int m, int s) { return s + m * 60 + h * 3600;}int main(){ int n; cin >> n; if (n == 0)原创 2021-03-13 17:31:26 · 279 阅读 · 0 评论 -
7-1 Arithmetic Progression of Primes (20 分)
#include <iostream>#include <algorithm>using namespace std;bool is_prime[100005];int MAXP, n;int main(){ cin >> n >> MAXP; fill(is_prime + 2, is_prime + 1 + MAXP, true); for (int i = 2; i <= MAXP; i++) { for (int j原创 2021-03-13 17:30:47 · 607 阅读 · 1 评论 -
7-4 Recycling of Shared Bicycles (30 分)
#include <iostream>#include <queue>#include <vector>#include <algorithm>using namespace std;struct Node { int v, d; Node() {} Node(int v, int d) :v(v), d(d) {}};vector<vector<Node>> adj;void dijkstra(int s原创 2021-03-13 17:32:35 · 615 阅读 · 5 评论