PAT甲级
PAT甲级
神秘的义勇神驹
这个作者很懒,什么都没留下…
展开
-
2020年7月25日春季PAT甲级满分记录
emmmmm其实我就是个弱鸡,3月份的时候刷题准备来着,然后一直玩到保研夏令营,真是太作死了.......现在想想都不知道能不能过浙大计算机的初审,o(╥﹏╥)o下面写的主要是思路和考试的心理历程:第一题:直接判断素数每次用string的erase(s.begin()) 再stoi(s)即可一开始还写的打表然后内存超限了- - 太久没写了这题考试时正确率应该有个50%第三题:没错弄完第一题,我看了下正确率,虽然此时提交数还很少,但果断做第三题(一般前两题有点小坑,按以往原创 2020-07-30 10:35:53 · 831 阅读 · 1 评论 -
1131 Subway Map (30分)
考察dfs的一道题,另外输出的时候也要注意1、题目给的信息如何使用vector<vector<int>> v(10000);保存从该station能到达的所有其他stationunordered_map<int,int> line line[x*10000+y]来记录线路。2、dfs如何设计题目要求的是the quickest path,...原创 2020-03-20 18:38:39 · 147 阅读 · 0 评论 -
1111 Online Map (30分)
就是普通的Dijkstra。不过这次是两个。第一个让求最短路径(如果不唯一要求时间最短)->d[maxn],t[maxn],visit[maxn]选 p[maxn]存储父节点第二个让求最快路径(如果不唯一要求点最少) ->t[maxn],node[maxn],visit[maxn]选 p[maxn]存储父节点注意从1到2 数组t visit p要重置。最后判断相...原创 2020-03-20 12:31:43 · 364 阅读 · 2 评论 -
1139 First Contact (30分)
可以直接按照题目的要求做。题目要求:AloveB,先找到A的同性好友C,再找到BC的共同好友D,且D的性别与B相同。虽然题目中说AB是同性or异性但其实处理起来是一样的。如果想做的漂亮就需要一些小技巧and思考。测试点2 应该是有-0000这样的数据,需要用字符串接收。#include<bits/stdc++.h>using namespace std;cons...原创 2020-03-20 11:24:52 · 287 阅读 · 0 评论 -
1147 Heaps (30分)
给出一个完全二叉树(用数组存储),判断是不是堆(写出max min not),然后给出后序遍历的结果。判断max min的方法:对所有有孩子的结点,验证是否孩子都小于父母or都大于父母#include<bits/stdc++.h>using namespace std;const int maxn=1010;int d[maxn];int m,n;void postO...原创 2020-03-19 11:09:00 · 184 阅读 · 0 评论 -
1146 Topological Order (25分)
依然是图的验证题,那么只需要判断是否是拓扑排序即可。拓扑排序要求每次的点入度为0。//有向无环图vector<int> v[maxn];//记录从该顶点出去的点int indegree[maxn];//入度,但是要重新使用怎么办?int temp[maxn];//循环时重新使用#include<bits/stdc++.h>using namespac...原创 2020-03-19 11:04:19 · 138 阅读 · 0 评论 -
1145 Hashing - Average Search Time (25分)
主要是要知道平方探测法从何时探测到何时算结束,同样的题目1078平方探测法(Quadratic Probing) 二次探测平方探测法:以增量序列1^2 -1^2, 2^2, -2^2, …… , q^2, -q^2,且 q<= [ TableSize/2 ] 循环试探下一个存储地址。TableSize作为上界,却是可以证明得出的。使用平方探测法进行插入时,i的最大...原创 2020-03-19 10:59:16 · 135 阅读 · 0 评论 -
1151 LCA in a Binary Tree (30分)
不⽤建树~已知某个树的根结点,若a和b在根结点的左边,则a和b的最近公共祖先在当前⼦树 根结点的左⼦树寻找, 如果a和b在当前⼦树根结点的两边,在当前⼦树的根结点就是a和b的最近公共祖先, 如果a和b在当前⼦树根结点的右边,则a和b的最近公共祖先就在当前⼦树的右⼦树寻找。中序加先序可以唯⼀确定⼀棵树,在不构建树的情况下,在每⼀层的递归中,可以得到树的根结点,在此 时并⼊lca算...原创 2020-03-18 21:33:24 · 85 阅读 · 0 评论 -
1150 Travelling Salesman Problem (25分)
TS simple cycle if it is a simple cycle that visits every city; TS cycle if it is a cycle that visits every city, but not a simple cycle; Not a TS cycle if it is NOT a cycle that visits every city....原创 2020-03-18 21:01:30 · 82 阅读 · 0 评论 -
1149 Dangerous Goods Packaging (25分)
Now you are given a long list of incompatible goods, and several lists of goods to be shipped. You are supposed to tell if all the goods in a list can be packed into the same container.给一个不兼容货物的列表,然...原创 2020-03-18 20:53:36 · 144 阅读 · 0 评论 -
1148 Werewolf - Simple Version (20分)
Now you are asked to solve a harder version of this problem: given that there were N players, with 2 werewolves among them, at least one but not all the werewolves were lying, and there were exactly 2...原创 2020-03-18 20:48:20 · 85 阅读 · 0 评论 -
1155 Heap Paths (30分)
One thing for sure is that all the keys along any path from the root to a leaf in a max/min heap must be in non-increasing/non-decreasing order.Your job is to check every path in a given complete bi...原创 2020-03-18 20:03:55 · 83 阅读 · 0 评论 -
1154 Vertex Coloring (25分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k...原创 2020-03-18 17:15:38 · 87 阅读 · 0 评论 -
1153 Decode Registration Card of PAT (25分)
for a type 1 query, the output format is the same as in input, that is, CardNumber Score. If there is a tie of the scores, output in increasing alphabetical order of their card numbers (uniqueness of ...原创 2020-03-18 16:58:15 · 88 阅读 · 0 评论 -
1152 Google Recruitment (20分)
consecutive 连续的输出第一个k位的连续的是素数的字符串,如果没有就输出404话说这里的note说了还不如不说-,-,害得我改错了错误点: 注意循环那里写到i<=s.length()-k#include<bits/stdc++.h>using namespace std;bool isP(int a){ if(a==1||a==0) re...原创 2020-03-18 15:51:02 · 114 阅读 · 1 评论 -
PAT(甲级)2019年秋季考试 结题报告
7-1Forever"Forever number" is a positive integer A with K digits, satisfying the following constrains:the sum of all the digits of A is m; the sum of all the digits of A+1 is n; and the greate...原创 2020-03-18 12:18:45 · 215 阅读 · 0 评论 -
PAT(甲级)2019年春季考试 解题报告
这次刚做30分钟过了两题就被打断了...然后再看就没时间了,不过这次的第三题第四题确实麻烦一些7-1Sexy PrimesSexy primes are pairs of primes of the form (p, p+6), so-named since "sex" is the Latin word for "six". (Quoted from http://mathworld...原创 2020-03-18 09:21:47 · 268 阅读 · 0 评论 -
PAT(甲级)2019年冬季考试 解题报告
这真的是2019年最简单的一次考试了把...感觉春秋的就很难满分至于一些失分陷阱,如果在平时好好总结自己容易出错的点,也基本不会踩坑~7-1Good in CWhen your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?Input...原创 2020-03-16 17:26:58 · 489 阅读 · 6 评论 -
1144 The Missing Number (20分)
emmmm确实用map简单#include <iostream>#include <map>using namespace std;int main() { int n, a, num = 0; cin >> n; map<int, int> m; for (int i = 0; i < n; i++) { ci...原创 2020-03-19 10:23:37 · 92 阅读 · 0 评论 -
1143 Lowest Common Ancestor (30分) [LCA]
因为给出这么一串序列来,二叉搜索树已经定型了那么LCA直接找最先出现的a b中间的数就好#include<bits/stdc++.h>using namespace std;const int maxn=10010;int d[maxn];map<int,int> mp;int main(){ //左边的小 右边的大 int m,n,an...原创 2020-03-19 11:19:50 · 79 阅读 · 0 评论 -
1142 Maximal Clique (25分)
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adj...原创 2020-03-19 11:18:32 · 143 阅读 · 0 评论 -
1141 PAT Ranking of Institutions (25分)
结构体排序模板题注意要求最后总合成绩取整#include<bits/stdc++.h>using namespace std;const int maxn=100100;struct Node{ double score; string name; int num;}school[maxn];bool cmp(Node a,Node b){...原创 2020-03-19 11:17:44 · 113 阅读 · 0 评论 -
1140 Look-and-say Sequence (20分)
一截一截写,这个写法可以直接记下来,蛮多问题考这个#include<bits/stdc++.h>using namespace std;int main(){ string d; int n; cin>>d>>n; n--; while(n--){ //注意是一截一截地写 string a; ...原创 2020-03-19 11:15:54 · 111 阅读 · 0 评论 -
1138 Postorder Traversal (25分)
两种原创 2020-03-19 11:33:27 · 146 阅读 · 0 评论 -
1137 Final Grading (25分)
用map把名字变数字来索引;一开始的编程成绩决定要不要存储,所以之后都判断下,如果没有存储就跳过#include<bits/stdc++.h>using namespace std;const int maxn=10100;struct Node{ string id; int gp,gm=-1,gf=-1; int g=-1;}node[m...原创 2020-03-19 11:23:08 · 93 阅读 · 0 评论 -
1136 A Delayed Palindrome (20分)
1 将字符串倒置与原字符串⽐较看是否相等可知s是否为回⽂串 2 字符串s和它的倒置t相加,只需从头到尾相加然后再倒置(记得要处理最后⼀个进位carry,如果有 进位要在末尾+’1’) 3 倒置可采⽤algorithm头⽂件⾥⾯的函数reverse(s.begin(), s.end())直接对s进⾏倒置参考柳神代码,这样写简洁了许多测试点错误的可能是:一开始就是...原创 2020-03-15 08:50:29 · 143 阅读 · 0 评论 -
1135 Is It A Red-Black Tree (30分)
There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:(1) Every node is either red or black. (2) The root is black. (3) Every...原创 2020-03-15 08:50:11 · 107 阅读 · 0 评论 -
1134 Vertex Cover (25分)
A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set.顶点的集合,使得图中每条边都至少有一个顶点在其中那么每次给出点的集合,用hash标记下判断是否覆盖所有边即可~⽤vector v[n]保...原创 2020-03-15 08:49:48 · 106 阅读 · 0 评论 -
1133 Splitting A Linked List (25分)
1、视作链表模板题,分类转成排序#include<bits/stdc++.h>using namespace std;const int maxn=100100;struct node{ int address,data,next; int fen; int order;}listn[maxn];bool cmp(node a,node b){...原创 2020-03-15 08:48:27 · 179 阅读 · 0 评论 -
1132 Cut Integer (20分)
在取余操作前注意 被操作数是否可能为0#include<bits/stdc++.h>using namespace std;int main(){ int n;cin>>n; while(n--){ string c; cin>>c; string a=c.substr(0,c.leng...原创 2020-03-15 08:48:06 · 77 阅读 · 0 评论 -
1130 Infix Expression [dfs]
dfs深度优先搜索原创 2020-03-20 11:37:05 · 106 阅读 · 0 评论 -
1129 Recommendation System
主要是这里的一些操作可能不太熟悉重载运算符+删除插入结构体变量这里~#include<bits/stdc++.h>using namespace std;const int maxn=50100;//重载<运算符struct node{ int value; int cnt; bool operator < (const node ...原创 2020-03-15 08:47:43 · 95 阅读 · 0 评论 -
1128 N Queens Puzzle (20分)
八皇后问题~不过这次是给出你解决方案,你来判断OK不OK那么结合题目的输入,八皇后要求:1、一行只有一个 可以直接忽略2、一列只有一个 输入必须都是不同值3、斜对角线 遍历之前的判断abs(j-i)==abs(d[i]-d[j])#include<bits/stdc++.h>using namespace std;bool Quee...原创 2020-03-15 08:47:19 · 108 阅读 · 0 评论 -
1127 ZigZagging on a Tree (30分)
题目要求:根据中序和后序建树,然后"zigzagging order" 进行层序遍历原创 2020-03-20 16:35:42 · 108 阅读 · 0 评论 -
1126 Eulerian Path (25分)
It has been proven that connected graphs with all vertices of even degree have an Eulerian circuit, and such graphs are called Eulerian. If there are exactly two vertices of odd degree, all Eulerian p...原创 2020-03-15 08:47:00 · 81 阅读 · 0 评论 -
1125 Chain the Ropes (25分)
#include<bits/stdc++.h>using namespace std;const int maxn=10010;int d[maxn];int main(){ int n; cin>>n; for(int i=0;i<n;i++) cin>>d[i]; sort(d,d+n); double...原创 2020-03-15 08:46:39 · 88 阅读 · 0 评论 -
1124 Raffle for Weibo Followers (20分)
#include<bits/stdc++.h>using namespace std;set<string> people;int main(){ int m,n,s; cin>>m>>n>>s; if(m<s){ cout<<"Keep going...";return ...原创 2020-03-15 08:45:52 · 122 阅读 · 0 评论 -
1123 Is It a Complete AVL Tree (30分)
本题考查的就是树的基本操作原创 2020-03-20 16:32:25 · 160 阅读 · 0 评论 -
1122 Hamiltonian Cycle (25分)
a simple cycle that contains every vertex in a graph.那么思考下如何判断:1、cycle 要求v1=vn2、simple 要求每个顶点只出现一次,这个条件结合每个顶点都要出现,可以按如下判断:n=N+1且用set s记所有顶点,s.size()=N3、cycle 要求是连通的,这也很简单,判断每次g[v[i]][v[i-1]]...原创 2020-03-14 17:32:32 · 118 阅读 · 0 评论 -
1121 Damn Single (25分)
还是用set对每位客人,如果发现他对象已经来了,不仅不插入,还要把他对象去掉如果发现他是单身狗or他对象还没来,暂且把他插入#include<bits/stdc++.h>using namespace std;map<int,int> mp;set<int> s;int main(){ int n,m; cin>&g...原创 2020-03-14 17:24:39 · 74 阅读 · 0 评论