PAT甲级刷题
YYHCODE
这个作者很懒,什么都没留下…
展开
-
PAT甲级暂时不用刷的题
1007动态规划10141017大模拟1026大模拟1040动态规划1045动态规划1068动态规划1010二分法1016 1033 1056 1057 1066原创 2021-08-21 16:50:13 · 46 阅读 · 0 评论 -
2021年秋季甲级91分
后三个题一个半小时AC,第一个题最后都只是11分。。。最后10分钟想起来用map,打表太大了。但是调试好切回去就到时间了????。留有遗憾。第二个题第一次交好像是19分,改了一下就AC了。后两个都是一次性AC。主要是觉得一个半小时做20分的题,自己就有点松懈了,一开始想过用map但是觉得打表好像也可以就陷进去了。...原创 2021-09-26 11:24:28 · 102 阅读 · 0 评论 -
PATA1004_层次遍历(难度:⭐️⭐️)
就是层次遍历的模版,不算难。#include <bits/stdc++.h>using namespace std;struct node { int layer; vector<int> v;}Node[110];vector<int> ans(110);int main() { int n, m, k, a, layer = 0; scanf ("%d %d", &n, &m); for (int原创 2021-09-01 17:53:03 · 100 阅读 · 0 评论 -
PATA1005_简单题(难度:⭐️/2)
没难度上代码。#include <bits/stdc++.h>using namespace std;string v[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};int main() { string s; int sum = 0; cin >> s; for (int i = 0 ; i < s.siz原创 2021-09-01 17:25:18 · 66 阅读 · 0 评论 -
PATA1006_简单题(难度:⭐️)
这个题秒杀了。#include <bits/stdc++.h>using namespace std;map<string, string> in, out;int main() { string id, IN, OUT; int m; scanf ("%d", &m); for (int i = 0; i < m; i++) { cin >> id >> IN >> OUT原创 2021-09-01 17:17:23 · 91 阅读 · 0 评论 -
PATA1007_船新版本!测试点坑!
输入的时候记录下非负数的位置(不要少了0),然后从第一个非负数加到最后一个非负数的位置。中间注意:如果当前sum小于0就break,因为就算后面有更大的数加负数也会变小。测试点5应该就是有个位置是0其余都是负数:3 -1 0 -1,应该输出0 0 0。仔细读题!#include <bits/stdc++.h>using namespace std;vector<int> pstv, v;int main() { int n, x, maxNum = 0,原创 2021-09-01 17:04:25 · 103 阅读 · 0 评论 -
PATA1008_简单题(难度⭐️/2)
大????只需要注意有测试点是有重复楼层 1 1,要多停5秒。#include <bits/stdc++.h>using namespace std;int main() { int k, ans = 0, now, pre = 0; scanf ("%d", &k); for (int i = 0; i < k; i++) { scanf ("%d", &now); if (now > pre) an原创 2021-09-01 16:09:31 · 80 阅读 · 0 评论 -
PATA1009_模拟(难度:⭐️⭐️)
难在有几个单词不认识,要靠测试用例猜。#include <bits/stdc++.h>using namespace std;struct node { int e; double a;};vector<node> v, ans;map<int, double> mp;int main () { int k, e; double a; scanf ("%d", &k); for (int i = 0原创 2021-09-01 15:52:13 · 78 阅读 · 0 评论 -
PATA1101_简单题(难度:⭐️/3)
#include <bits/stdc++.h>using namespace std;vector<char> v;int main() { double ans = 0.65; for (int i = 0; i < 3; i++) { double maxD = 0, b1, b2, b3; scanf ("%lf %lf %lf", &b1, &b2, &b3); maxD .原创 2021-09-01 15:23:41 · 83 阅读 · 0 评论 -
PATA1012_思路!简短代码,测试点!(难度:⭐️⭐️⭐️⭐️)
为了不用写四个cmp,可以用4个vector来表示四种成绩。然后用一个map<string, vector<node>>来记录顺序。为了实现优先级我把每科的名字用a ~ d重定义了一下,最后也只需要 char数组[ 科目- 'a']就行了,详情看代码。// a = avg, b = C, c = M, d = E一开始我是用set<string>来自动排序,例如第一名1和科目a就是,"1a"。但是这样会有两个问题,"11a"会排在"1a"前面,也就是说..原创 2021-09-01 11:59:09 · 118 阅读 · 0 评论 -
PATA1013_连通图(难度:⭐️⭐️⭐️)
需要修补的路就是连通图数量 - 1.#include <bits/stdc++.h>using namespace std;vector<vector<int>> v;bool vis[1010];void DFS (int s) { if (vis[s] == true) return; vis[s] = true; for (int i = 0; i < v[s].size(); i++) { int now原创 2021-08-31 20:50:03 · 76 阅读 · 0 评论 -
PATA1015_进制转换和素数(难度:⭐️⭐️)
PAT早起的题目有时候题意我读不太明白,我一开始以为是在d进制下,正序和反序都是素数。还要转化为10进制。。。我太菜了#include <bits/stdc++.h>using namespace std;bool isPrime (int n) { if (n <= 1) return false; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false;原创 2021-08-31 19:58:47 · 83 阅读 · 0 评论 -
PATA1018_Dij+ DFS回溯(难度:⭐️⭐️⭐️)
这种题突出一种折磨,我一开始理解的是后面站点收集的也可以用于前面站点,毕竟你是要回来的嘛。但是居然不考虑后面多出来的,关键是题目根本就没说。。。考虑后面的还要更复杂,我写了120行,不考虑的话90多行。如果考虑多了,测试点5 7过不了。//3:55 ~ #include <bits/stdc++.h>using namespace std;const int maxn = 520;const int INF = 999999999;int G[maxn][max.原创 2021-08-31 17:24:16 · 81 阅读 · 0 评论 -
PATA1019_STL(难度:⭐️)
一开始用的string,会发现基数是大于10的时候就不行了。乖乖用vector吧。#include <bits/stdc++.h>using namespace std;int main() { int a, b; vector<string> s, rver; scanf ("%d %d", &a, &b); while (a != 0) { s.push_back(to_string(a % b));原创 2021-08-31 15:53:06 · 56 阅读 · 0 评论 -
PATA1020_后序中序建树(难度:⭐️⭐️)
前序,后序,层次和中序都能唯一确定一棵????。在加一个层次遍历。#include <bits/stdc++.h>using namespace std;struct tree { int val; tree *lc, *rc;};vector<int> post, in, ans;tree *build (int inL, int inR, int postL, int postR) { if (inL > inR) return NU原创 2021-08-31 15:37:40 · 86 阅读 · 0 评论 -
PATA1021_DFS(难度:⭐️⭐️⭐️)
自己第一次写36行写完了,感觉很简单。一提交测试点3超时,然后想办法在DFS里面剪枝,但是并没有什么用。然后就去看了一下柳神的代码,才知道一个结论。第一次DFS记录最远节点(它一定是全局最远的),然后再用其中一个再DFS一次。应该是你局部的最远路径,那么一定是全局最远的一个子路径。#include <bits/stdc++.h>using namespace std;int n, a, b, cnt = 0, cmpt = 1, maxH = 0, flag = 0;stru原创 2021-08-31 14:40:43 · 81 阅读 · 0 评论 -
PATA1022_STL(难度:⭐️⭐️)
下面是老实人做法,做完才想起来一个更简便的方法。如果怕书名,人名或是其他的重名,在map映射的时候再前面 + "num" (1 ~ 5),这样就保证不会冲突,而且只用一个map会简洁很多。用map<string, set<int>>。然而这个题并没有毁重复的情况。。。下面是简短代码#include<bits/stdc++.h>using namespace std;unordered_map<string, set<int>> m原创 2021-08-31 10:44:09 · 88 阅读 · 0 评论 -
PATA1023_大整数运算(难度:⭐️⭐️)
如果把这个题做好了,那么下一个题加法部分可以直接c + v。因为我是倒着做的,所以我用的是1024的????#include <bits/stdc++.h>using namespace std;string Add (string a, string b) { int flag = 0; for (int i = a.size() - 1; i >= 0; i--) { int u = a[i] - '0', v = b[i] - '0';原创 2021-08-31 09:30:09 · 74 阅读 · 0 评论 -
PATA1024_大整数运算(难度:⭐️⭐️)
注意有两个测试点是,输入的时候就会有回文串。#include <bits/stdc++.h>using namespace std;string Add (string a, string b) { int flag = 0; for (int i = a.size() - 1; i >= 0; i--) { int u = a[i] - '0', v = b[i] - '0'; // cout << u <<原创 2021-08-31 09:20:53 · 65 阅读 · 0 评论 -
PATA1025_STL(难度:⭐️⭐️)
没啥难度上代码。#include <bits/stdc++.h>using namespace std;struct node { string id; int g, lct, lctRank;};vector<node> ans;vector<vector<node>> v;bool cmp (node a, node b) { if (a.g != b.g) return a.g > b.g; ret原创 2021-08-30 21:38:10 · 101 阅读 · 0 评论 -
PATA1027_简单题(难度⭐️ / 2)
上代码。#include<bits/stdc++.h>using namespace std;char c[13] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'};int main() { int a, b, x; cin >> a >> b >> x; cout << "#"; printf ("%c%c", c[a / 13], c[a原创 2021-08-30 20:16:29 · 72 阅读 · 0 评论 -
PATA1028_STL(难度:⭐️)
没难度上代码。#include <bits/stdc++.h>using namespace std;struct node { int id, g; string name;};bool cmp1 (node a, node b) { return a.id < b.id;}bool cmp2 (node a, node b) { if (a.name != b.name) return a.name < b.name; e原创 2021-08-30 19:53:40 · 83 阅读 · 0 评论 -
PATA1029_迷茫了(难度:负⭐️)
这个题纯属降智,直接放一个数组里用sort就行。我还以为数据量很大,然后必须要用特殊的方法,我人傻了。下面是最简单想法#include <bits/stdc++.h>using namespace std;int main() { int n, m; cin >> n; vector<int>s1(n); for (int i = 0; i < n; i++) scanf("%d", &s1[i]); cin >> m原创 2021-08-30 18:10:52 · 61 阅读 · 0 评论 -
PATA1030_图的遍历(难度:⭐️⭐️)
这个题难度在于有多个路径,需要DFS回溯判断最少花费。#include<bits/stdc++.h>using namespace std;const int maxn = 520;const int INF = 999999999;int n, m, start, dst, c1, c2, d, cost, minCost = INF;int G[maxn][maxn], dis[maxn], W[maxn][maxn];vector<vector<int>原创 2021-08-30 17:13:33 · 77 阅读 · 0 评论 -
PATA1033_贪心(难度:⭐️⭐️⭐️⭐️)
这个题我觉得很难,因为好多东西刚看题目想不到,只有慢慢写出来才能发现一些隐藏的东西。主要的思路就是:如果当前站点是最大距离(Cmax * Davg)内最便宜的就加满,如果不是就只加到下一个最便宜的站点内。有一个测试点第一个加油站起点并不是0,记得判断第一个加油站的起点。#include <bits/stdc++.h>using namespace std;struct node { double dis, p;};bool cmp (node a, node b)原创 2021-08-30 16:20:10 · 97 阅读 · 0 评论 -
PATA1031_模拟(难度:⭐️⭐️)
这个题把关系搞明白。2n1 + n3 - 2 = N. n1 = N / 3; n3 = ( N % 3) + n1;多出来的全部要给底部。#include <bits/stdc++.h>using namespace std;int main() { string s; int n, n1, n3, span, len; cin >> s; len = s.size(); n1 = (len + 2)...原创 2021-08-30 10:29:32 · 85 阅读 · 0 评论 -
PATA1132_链表(难度:⭐️⭐️)
有两个测试点比较特殊。第一个:可能是londing ing这种情况。第二个:有一个字符串是空的。#include <bits/stdc++.h>using namespace std;struct node { char c; int next;}Node[100000];vector<int> v1, v2;int main() { int fAd1, fAd2, n, ad, next; char c; sca..原创 2021-08-28 20:12:22 · 70 阅读 · 0 评论 -
PATA1034_图的遍历(难度:⭐️⭐️⭐️⭐️)
这个题自己重新做一次。这个是DFS的做法#include <bits/stdc++.h>using namespace std;int W[2010], G[2010][2010];int idnum = 1, k, head, maxTime = 0;bool vis[2010];unordered_map<string, int> sToInt;map<string, int> ans;unordered_map<int, st.原创 2021-08-28 10:54:25 · 94 阅读 · 0 评论 -
PATA1135_c++基础(难度:⭐️)
没难度上代码。#include <bits/stdc++.h>using namespace std;vector<string> ans;int main() { int n; string name, pw; scanf ("%d", &n); for (int i = 0; i < n; i++) { int flag = 0; cin >> name >> pw;原创 2021-08-27 20:27:52 · 75 阅读 · 0 评论 -
PATA1036_STL(难度:⭐️)
没难度上代码。#include <bits/stdc++.h>using namespace std;struct node { string name, id; int grade;};vector<vector<node>> v(2);bool cmp1 (node a, node b) { return a.grade > b.grade;}bool cmp2 (node a, node b) { retur原创 2021-08-27 20:11:57 · 63 阅读 · 0 评论 -
PATA1037_模拟(难度:⭐️⭐️)
没难度上代码。#include <bits/stdc++.h>using namespace std;vector<int> v1, v2;int main() { int n, sum = 0; scanf ("%d", &n); v1.resize(n); for (int i = 0; i < n; i++) scanf ("%d", &v1[i]); scanf ("%d", &n);原创 2021-08-27 19:55:57 · 78 阅读 · 0 评论 -
PATA1038_STL(难度:⭐️⭐️⭐️)
这个题自己写cmp写不出来,看了柳神的代码只能说明白了cmp可以自动排列组合.能用a + b < b + a来返回最小的值,但是具体cmp内部实现还没想清楚,先用着。#include <bits/stdc++.h>using namespace std;vector<string> v;string sMIn = "9999999999999999999";bool cmp (string a, string b) { return a + b &l.原创 2021-08-27 11:57:46 · 87 阅读 · 0 评论 -
PATA1039_map(难度:⭐️⭐️)
如果这个题不允许用map(数据量超大),可以用一位数组来映射,把名字转换为数字,仍然是唯一的。#include <bits/stdc++.h>using namespace std;unordered_map<string, vector<int>> mp;int main() { int n, k, course, num; string name; scanf ("%d %d", &n, &k); for (原创 2021-08-27 11:22:07 · 80 阅读 · 0 评论 -
PATA1040_模拟(难度:⭐️⭐️)
怎么说呢,简单上代码。#include <bits/stdc++.h>using namespace std;bool cmp (string s) { for (int i = 0, j = s.size() - 1; i < s.size() && j > i; i++, j--) { if (s[i] != s[j]) return false; } return true;}int main() {原创 2021-08-27 10:44:39 · 76 阅读 · 0 评论 -
PATA1041_map(难度:⭐️)
没难度上代码。#include <bits/stdc++.h>using namespace std;unordered_map<int, int> mp;vector<int> v;int main() { int n, a, flag = 1; scanf ("%d", &n); for (int i = 0; i < n; i++) { scanf ("%d", &a); m原创 2021-08-27 10:14:13 · 49 阅读 · 0 评论 -
PATA1142_模拟(难度:⭐️⭐️)
这个题难度在于思维,一定要明确变的是位置,调整位置的数组不用变。还有一点要注意的是:由于1~13都是S的,这里c[13 % 13]会有问题,要减去1再%13。#include <bits/stdc++.h>using namespace std;vector<int> shf(55), pre(55), now(55);char c[4] = {'S', 'H', 'C', 'D'};int main() { int k; scanf ("%d",原创 2021-08-27 10:05:07 · 87 阅读 · 0 评论 -
PATA1044_二分查找(难度:⭐️⭐️⭐️)
这个题暴力求解的话,能得21分。就是每一个都从头到尾加一次。显然有很多重复的没有必要的加法运算。我一开始就是想着要避免重复的加法运算但是昨天没做出来,就暴力求解。今早上脑袋不晕,很快就写出来了,其实就是偷懒没有在草稿纸上模拟一下,并不难。一定记得就是要用上一次满足等于或者大于给的值,他们的坐标。不要又从头加起来!下面是满分算法。#include<bits/stdc++.h>using namespace std;struct node { int u, v,..原创 2021-08-27 09:59:37 · 100 阅读 · 0 评论 -
PATA1046_模拟(难度:⭐️⭐️)
#include <bits/stdc++.h>using namespace std;vector<int> v;int main() { int n, d, k, ina, inb, sum = 0, a, b; scanf ("%d", &n); v.resize(n + 1); for (int i = 0; i < n; i++) { scanf ("%d", &d); v...原创 2021-08-26 19:42:04 · 94 阅读 · 0 评论 -
PATA1047_排序(难度:⭐️)
没难度上代码。#include <bits/stdc++.h>using namespace std;vector<vector<string>> v;bool cmp (string a, string b) { return a < b;}int main() { int n, k, m, course; string name; scanf ("%d %d", &n, &k); v.res原创 2021-08-26 10:46:12 · 61 阅读 · 0 评论 -
PATA1048_简单题(难度:⭐️)
没难度上代码。#include <bits/stdc++.h>using namespace std;struct node { int v1, v2;};vector<node> ans;bool cmp (node a, node b) { return a.v1 < b.v1;}int mp[1010];int main() { int n, m, a, v1, v2; scanf ("%d %d", &n,原创 2021-08-26 10:28:52 · 100 阅读 · 0 评论