
备战2021/3/13PAT
华师少女的梦
血肉苦弱,机械飞升!
展开
-
进阶实验6-3.5 关键活动 (30 分)
#include<cstdio>#include<vector>#include<queue>#include<stack>#define INF 65535#define MAXV 105using namespace std;int n,m,indegree[MAXV];int flex[MAXV][MAXV];struct ENode{ int w,weight; ENode(int _w, int _weight) : w(_.原创 2021-03-12 16:55:24 · 135 阅读 · 0 评论 -
7-4 Chemical Equation (30 分) (解释详细)
7-4 Chemical Equation (30 分)Achemical equationis the symbolic representation of a chemical reaction in the form of symbols and formulae, wherein the reactant entities are given on the left-hand side and the product entities on the right-hand side. For ..原创 2021-03-09 12:37:57 · 2118 阅读 · 5 评论 -
PAT(甲级)2020年春季考试
小结:很常规的一套题,每道题前面写一点小提示。7-1 Prime Day (20 分)The above picture is from Sina Weibo, showing May 23rd, 2019 as a very cool "Prime Day". That is, not only that the corresponding number of the date20190523is a prime, but all its sub-strings ended at the ..原创 2021-03-07 20:48:53 · 583 阅读 · 0 评论 -
2020浙江大学计算机与软件学院保研上机题(代码简明)
小结:这套题比2019年浙大保研上机质量高太多了。考到的知识点有深度优先搜索、并查集、优先级队列(最大最小堆)。第二题是个很有意思的题,我使用了三指针法做,应该是这道题最简单的解法而且时间复杂度是n。这套题的第二题和第四题都在卡时间复杂度,基本上暴力解法和最优解法每题会差10分左右。每个题代码都比较清晰简短所以只给一点小提示,相信能做到这套卷的都应该看得明白。7-1Standard Form of Polynomial(20分)The standard form of a polynomia原创 2021-03-06 11:26:31 · 2318 阅读 · 2 评论 -
浙江大学计算机与软件学院2019年保研上机
这套题跟2019年考研上机题难度差了几个数量级,建议完成时间不超过80分钟。7-1 Happy Numbers (20 分)Ahappy numberis defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits in base-ten, and repeat the process until t..原创 2021-03-04 19:57:26 · 483 阅读 · 1 评论 -
7-3 Left-View of Binary Tree (25 分)
7-3 Left-View of Binary Tree (25 分)Theleft-viewof a binary tree is a list of nodes obtained by looking at the tree from left hand side and from top down. For example, given a tree shown by the figure, its left-view is { 1, 2, 3, 4, 5 }Given the ino..原创 2021-03-04 17:23:34 · 251 阅读 · 1 评论 -
7-2 How Many Ways to Buy a Piece of Land (25 分)
7-2 How Many Ways to Buy a Piece of Land (25 分)The land is for sale in CyberCity, and is divided into several pieces. Here it is assumed that each piece of land has exactly two neighboring pieces, except the first and the last that have only one. One can原创 2021-03-04 16:57:50 · 193 阅读 · 1 评论 -
2020秋季甲级PAT 7-4 Professional Ability Test (30 分)
7-4 Professional Ability Test (30 分)Professional Ability Test (PAT) consists of several series of subject tests. Each test is divided into several levels. Level A is aprerequisite (前置要求)of Level B if one must pass Level A with a score no less thanS...原创 2021-03-04 16:19:33 · 1086 阅读 · 2 评论 -
2019浙江大学考研复试上机题 Ambulance Dispatch (30 分) ---测试点4
总体的解题思路:利用Dijkstra算法计算Na个救护中心与其余顶点的最短路径(时间上最短),并且保存救护中心和顶点之间的路径,若有多条也全部保存下来。当某个顶点v发出救护请求时,对于某个救护中心center,找出顶点v到center的经过街道数最少的路径。然后比较Na个救护中心中符合题意的那个救护中心(若有时间最小就就找时间最小,若时间相等就找车辆更多的救护中心,若时间都是最小且救护车数量都一样就找经过街道数最少的救护中心),当然只考虑还有救护车的救护中心。按照这个思路(Dijkstra+DF原创 2021-03-03 21:19:19 · 1337 阅读 · 1 评论 -
PAT小技巧记录(持续更新)
1、sscanf2、to_string()原创 2021-03-03 16:43:13 · 202 阅读 · 2 评论 -
2019浙江大学考研复试上机题
1.#include<cstdio>#include<cmath>#include<string>#include<vector>using namespace std;const int maxn = 20000;bool isPrime(long long x){ if(x<=1) return false; long long sqr = (int)sqrt(1.0*x); for(long long i=2; i<原创 2021-03-02 19:44:56 · 425 阅读 · 0 评论 -
1136 A Delayed Palindrome (20 分) bign数组开1000是不够的
bign的数组开1000是不够的,因为在边界条件下有可能在叠加的过程中位数会超过1000。在解题过程中数组要稍微开大一点,留一点冗余。#include<cstdio>#include<algorithm>#include<string>#include<iostream>using namespace std;const int maxn = 1010;//这里maxn取值大于1000struct bign{ int d[maxn]; i原创 2021-03-02 16:03:53 · 77 阅读 · 0 评论 -
1151 LCA in a Binary Tree (30 分) 测试点2
测试点2数据:5 5输出应该是:5 is an ancestor of 5.原创 2021-03-02 10:23:39 · 224 阅读 · 0 评论 -
1137 Final Grading (25 分)------记录一个错误
题目讲的是总成绩要超过60而不是期末成绩。一定要谨慎、细心的读题。#include<cstdio>#include<vector>#include<string>#include<map>#include<algorithm>#include<iostream>#include<cmath>using namespace std;struct student{ string name; int gp原创 2021-02-24 22:12:29 · 126 阅读 · 0 评论 -
1153 Decode Registration Card of PAT (25 分) 用printf进行输出
这道题的输出一定要用printf不能用cout,否则最后一个测试点会多接近100ms的运行时间。#include<cstdio>#include<vector>#include<map>#include<string>#include<algorithm>#include<iostream>using namespace std;struct node{ int site; int num;};struct.原创 2021-02-24 13:27:44 · 162 阅读 · 0 评论 -
1145 Hashing - Average Search Time (25 分)
这道题注意一点就好了,查询的范围是0到哈希表的表长。如果查询失败有两种情况:第一种是查到的一个格子,这个各子里什么都没有,那么查询失败的长度就是i+1。第二种情况是从0到哈希表长都查不到那么查询失败的长度就是哈希表长加1。#include<cstdio>#include<cmath>#include<algorithm>using namespace std;bool isPrime(int x){ if(x<=1) return false;.原创 2021-02-24 12:10:40 · 90 阅读 · 0 评论 -
1034 Head of a Gang (30 分) 如何对每一条边只访问一次
本题与一般的图遍历问题相区别的地方在于:对每个边仅访问一次。解决的办法是当访问到图中的某一个顶点u时,试图去访问该顶点u所有邻边,并且再访问过后就删除掉这条已经访问过的邻边,当然如果与该顶点u相连的另外一个顶点v未被访问过的话就深度优先访问v这个顶点直到所有的顶点都访问完毕。...原创 2021-02-19 11:13:49 · 103 阅读 · 0 评论 -
1107 Social Clusters (30 分) 给几组测试数据
63: 1 2 33: 4 5 63: 7 8 91: 11: 42: 1 4原创 2021-02-10 12:31:47 · 184 阅读 · 0 评论 -
1086 Tree Traversals Again (25 分)
#include<cstdio>#include<cstdlib>#include<stack>#include<vector>using namespace std;struct node{ int key; node* lchild; node* rchild;};vector<int> v;void postOrder(node* root){ if(root==NULL) return; postOrder(.原创 2021-02-04 20:36:49 · 76 阅读 · 0 评论 -
1103 Integer Factorization (30分) 测试点2 测试点5
我是从大数字往小数字去枚举的,如果照我这么写是过不了测试点的。因为在dfs函数中我是先做不选择该数,然后再选择该数。如果想要过测试点2的话改变这两句话的顺序即可。测试数据可以用100 5 2去跑一下。至于为什么会这样解释如下:如果不选择该数在前结果是:100 = 5^2 + 5^2 + 5^2 + 4^2 + 3^2如果选择该数在前结果是:100 = 6^2 + 4^2 + 4^2 + 4^2 + 4^2原因就是如果你的代码是不选择这个数的代码在前的话就会导致你深度优先一直到从10~6.原创 2021-01-30 18:28:31 · 487 阅读 · 4 评论 -
1100 Mars Numbers 对某些变量不进行初始化可能本地运行没有问题但是在oj上运行出现段错误
启发:在Stoi函数中,起初我忘记对ans进行初始化,在本地运行没有任何问题,但是提交到oj上就出现了段错误。以后再做题过程中如果发现本地运行没问题但是oj上出现段错误可以考虑是否是某些变量忘记初始化。#include<cstdio>#include<string>#include<iostream>#include<map>using namespace std;string low[13]={"tret","jan", "feb", ".原创 2021-01-29 16:19:32 · 202 阅读 · 0 评论 -
1060 Are They Equal 思路整理
总思路是把两个数都变成科学计数法然后比较有效位和指数是否相同。具体操作:(1)先要去掉前导零。如果是“000000”这种情况,去完前导零后字符串就没了,这时候要让指数e为0(2)此时可能字符串的第一位是小数点,这个时候把小数点去掉,然后找字符串中第一个不为零的字符所在的位置,并且把首个不为零的的字符前的所有零都去掉。另外每出现一个0,e--。注意有可能字符串是000.00000的情况,如果是这种情况要让e为0(3)此时字符串的第一位不是小数点而是一个非零数,去找小数点的位置然后去掉小数点,.原创 2021-01-29 15:36:22 · 109 阅读 · 0 评论 -
getline(cin,s)会读入缓冲区中的回车然后舍弃
#include<cstdio>#include<string>#include<iostream>using namespace std;int main(){ string s; char c; getline(cin,s); cout<<s<<"*****"; c = getchar(); printf("###%c$$$",c); }原创 2021-01-28 12:52:46 · 735 阅读 · 0 评论 -
1088 Rational Arithmetic (20分)
#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;LL gcd(LL a, LL b){ if(b!=0) return gcd(b,a%b); else return a;} struct fraction{ LL numer; LL denom;};fraction simp(fraction a){ LL common = gcd(abs(a.原创 2021-01-24 19:41:48 · 83 阅读 · 0 评论 -
1081 Rational Sum (20分)
#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;struct rational{ long long c,m;};LL gcd(LL a, LL b){ if(b==0) return a; else gcd(b,a%b);}LL gys(LL a, LL b){ LL c = gcd(a,b); LL ans = (a*b)/c; return an.原创 2021-01-22 20:05:36 · 82 阅读 · 0 评论 -
1104 Sum of Number Segments (20分)
double在大量的累加时会失真,本题采用long double尽可能的降低失真的程度以通过测试点2(10^5级别的数据量),当然如果数据量再大可能long double 也不好用了,但是对本题精度够了。#include<cstdio>int main(){ int n; long double a; scanf("%d",&n); long double ans=0; for(int i=1; i<=n; i++){ scanf("%llf",&.原创 2021-01-22 12:39:43 · 85 阅读 · 0 评论 -
pat考试数据类型的选择(做1049的经验)
pat考试中在数据接近2147483647时用long long类型可最大程度避免边界数据溢出的可能性。原创 2021-01-21 22:08:39 · 141 阅读 · 0 评论 -
1029 Median
#include<cstdio>#include<algorithm>using namespace std;long long A[200010];long long B[200010];int main(){ int n1,n2; scanf("%d",&n1); int i,j,k; for(i=0; i<n1; i++){ scanf("%lld",&A[i]); } scanf("%d",&n2); for(i.原创 2021-01-20 13:44:16 · 85 阅读 · 0 评论 -
1044 Shopping in Mars(双指针法)
#include<cstdio>#include<vector>using namespace std;const int inf = 1000000000;struct shape{ int left,right;};int chain[100010];int main(){ int n,m,i,j; vector<shape> v; scanf("%d%d",&n,&m); for(i=0; i<n; i++){ .原创 2021-01-19 12:16:20 · 125 阅读 · 0 评论 -
1010 Radix(溢出处理,二分法)
#include<cstdio>#include<iostream>#include<string>#include<algorithm>using namespace std;typedef long long LL;int toInt(char c){ if(c>='0'&&c<='9') return c-'0'; else return c-'a'+10;}LL toDecNorm(string s,.原创 2021-01-19 11:11:55 · 198 阅读 · 0 评论 -
1010 Radix (25分)
#include<cstdio>#include<algorithm>#include<iostream>#include<string>using namespace std;typedef long long LL;LL inf = (1LL<<63)-1;LL toInt(char c){ if(c>='0'&&c<='9') return c-'0'; else return 10+c-'a.原创 2021-01-18 21:29:37 · 85 阅读 · 0 评论 -
1033 To Fill or Not to Fill (25分)
#include<cstdio>#include<algorithm>using namespace std;struct station{ double price; double dis;}sta[510];bool cmp(station a, station b){ return a.dis<b.dis;}int main(){ double cmax,d,davg; int n; scanf("%lf%lf%lf%d",&cmax.原创 2021-01-17 15:30:36 · 65 阅读 · 0 评论 -
1075 PAT Judge (25分)
#include<cstdio>#include<algorithm>using namespace std;/*(1)没能过编译器的话就是-1,过了编译器至少有0分。(2)若没有一道题能过编译器的话或者,没有提交任何题目的人不出现在排名中。要想上排名至少要有一题要过编译器,哪怕只有0分。(3)按总分由高到低排名,完美解答题目的个数,id从小到大(4)没有提交为-2,提交了没过编译器为-1,提交了过了编译器为>=0。(5)没过编译器输出为0分。*/..原创 2021-01-14 19:52:36 · 105 阅读 · 0 评论 -
1016 Phone Bills (25分)
这道题主要是排完序之后的处理思路。首先先找出一个用户的所有的通话记录(边界);第二步边界里看这个用户有没有有效的通话记录,若有则把该用户所有的有效记录输出,若没有就找下一个用户。依此处理完所有的通话记录。#include<cstdio>#include<algorithm>#include<string>#include<iostream>using namespace std;struct record{ string name; int原创 2021-01-14 16:10:25 · 134 阅读 · 0 评论 -
1082 Read Number in Chinese (25分)
这个题的难点在于对前导零的处理,具体的处理思路如下:如果有前导0就要考虑前面有没有数,如果有数就要读,如果没数不读前导零且当前读的数字是第一个。若没有前导零,考虑前面有无数,有数的话输出空格没数的话不输出空格 。其中有无数用flag标识,flag==1为有数。#include<cstdio>char pinyin[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};void printDanwei.原创 2021-01-13 11:26:28 · 112 阅读 · 1 评论