PAT甲级
文章平均质量分 53
Mr0cheng
这个作者很懒,什么都没留下…
展开
-
PAT甲级 1131 - Subway Map
Each station interval belongs to a unique subway line.这句话比较重要,所以在进行dfs的时候记录区间,会方便很多。#include<bits/stdc++.h>using namespace std;const int maxn=10000+10;vector<pair<int,int> >vp;...原创 2018-02-26 11:48:49 · 419 阅读 · 0 评论 -
PAT甲级 1042
Shuffling MachineShuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collabor原创 2017-09-15 12:54:12 · 283 阅读 · 0 评论 -
PAT甲级 1037 -- 没有注释
1037. Magic Coupon (25)The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the原创 2017-07-22 13:51:29 · 266 阅读 · 0 评论 -
PAT甲级 1036 -- 没有注释
1036. Boys vs Girls (25)This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification:Each input原创 2017-07-22 13:44:57 · 237 阅读 · 0 评论 -
PAT甲级 1035 -- 没有注释
1035. Password (20)To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguis原创 2017-07-22 13:43:02 · 248 阅读 · 0 评论 -
PAT甲级 1034 -- 没有注释
1034. Head of a Gang (30)One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a r原创 2017-07-22 13:40:00 · 295 阅读 · 0 评论 -
PAT甲级 1134 - Vertex Cover
主要是考查了英文的能力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.a graph 指的是输入的m条边组成的图a vertex cover 指得是查询时输入的点(判断是否为ver...原创 2018-02-26 08:58:31 · 230 阅读 · 0 评论 -
PAT甲级 1066 - Root of AVL Tree
AVL左旋和右旋操作:LL时,需要进行右旋RR时,需要进行左旋LR时,先左旋再右旋RL时,先右旋再左旋所以判断当前状态后,只需左右旋两个基本操作。这两个基本操作,需要参考一个比较的不平衡树来写代码。#include<bits/stdc++.h>using namespace std;struct node{ node *l,*r; int ...原创 2018-02-26 15:37:49 · 277 阅读 · 0 评论 -
PAT甲级1091 - Acute Stroke
相当于一个连通图,只不过方向由二维的四个方向改成了三维上的6个方向。找到每个连通子图,判断是否大于或等于t。最后计算总和即可。这个不能用dfs递归的进行,会出现段错误。改成bfs,可以AC。#include<bits/stdc++.h>using namespace std;int m,n,l,t;bool in[60+4][1286+4][128+4],visite...原创 2018-02-26 17:32:10 · 233 阅读 · 0 评论 -
PAT甲级 1133 - Splitting A Linked List
这里可以分成三类,用三个vector保存。第一类是小于0的;第二类是大于0但是小于k的;第三类是大于k的;但我是直接使用sort排序里面的cmp重写做的(注意使用stable_sort就行了)。#include<bits/stdc++.h>using namespace std;const int maxn=100000+10;int startAddress,n,k;st...原创 2018-03-06 13:56:33 · 219 阅读 · 0 评论 -
PAT甲级 1135 - Is It A Red-Black Tree
主要是建树,可以用指针也可以用数组判断的话回溯判断两个点 左右孩子的当前的黑节点数目是否一样判断当前是否为红色,则孩子节点为黑色成立与否根节点要为黑色,故最后需要确认#include<bits/stdc++.h>using namespace std;const int maxn=30+2;bool flag;int inOrder[maxn],preOrder...原创 2018-02-25 13:18:32 · 276 阅读 · 0 评论 -
PAT甲级 1138 - Postorder Traversal
根据中序和前序序列建树递归回溯时第一个节点即为后序访问的第一个节点#include<bits/stdc++.h>using namespace std;const int maxn=50000+10;bool flag=false;int ans;int inOrder[maxn],preOrder[maxn];void dfs(int preL,int pr...原创 2018-02-25 11:07:27 · 289 阅读 · 0 评论 -
PAT甲级1136 - A Delayed Palindrome
string加法操作符重载string& assign (InputIterator first, InputIterator last);string& assign (const string& str, size_t subpos, size_t sublen = npos);void reverse (BidirectionalIterator first,...原创 2018-02-25 10:02:04 · 238 阅读 · 0 评论 -
PAT甲级 1119. Pre- and Post-order Traversals
和一般的中序和前序搭配建树不同,这里一定要分清每次递归要做的子任务。就是将当前preOrder的第一个看成根节点,然后去划分根节点的左右子树(因为NLR)。而且,如果当前的区间只有两个节点(其中一个看成根节点),又因为只有一个孩子节点,故无法判断该孩子节点是NLR中的L还是R。所以当preR-preL==1时,即不是独一无二的。#include<bits/stdc++.h>...原创 2018-03-09 15:19:27 · 264 阅读 · 0 评论 -
PAT甲级 1124 - Raffle for Weibo Followers
#include<bits/stdc++.h>using namespace std;const int maxn=1000+3;set<string> se;string str[maxn];vector<string> vec;int main(){ int m,n,s; scanf("%d %d %d",&m,&n,&a...原创 2018-03-01 17:53:33 · 204 阅读 · 0 评论 -
PAT甲级 1125 - Chain the Ropes
#include<bits/stdc++.h>using namespace std;const int maxn=10000+3;multiset<double> ms;int main(){ int n,t; scanf("%d",&n); for(int i=0;i<n;++i){ scanf("%d",&t); ...原创 2018-03-01 17:50:44 · 189 阅读 · 0 评论 -
PAT甲级 1126 - Eulerian Path
根据题目所给的条件进行判断即可。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 ...原创 2018-03-01 17:47:32 · 264 阅读 · 0 评论 -
PAT甲级1127 - ZigZagging on a Tree
通过中序和后序进行建树,在建树的过程中,记录当前深度,同一深度的PUSH到同一个vector容器中。因为建树过程中,LR是有序的,故同一层的左右顺序已经确定了。#include<bits/stdc++.h>using namespace std;const int maxn=30+2;int inOrder[maxn],postOrder[maxn];vector<i...原创 2018-03-01 17:43:24 · 240 阅读 · 0 评论 -
PAT甲级 1122 - Hamiltonian Cycle
注意题目的k的取值范围是不定的,所以在第二阶段的输入顶点序列不要用数组去存,直接用变量存取相应需要保存的值。#include<bits/stdc++.h>using namespace std;const int maxn = 200+10;bool edge[maxn][maxn];bool visited[maxn];int main(){ int n,m;...原创 2018-03-07 16:02:23 · 255 阅读 · 0 评论 -
PAT甲级 1033 - 未写注释
1033. To Fill or Not to Fill (25)With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the wa原创 2017-07-22 13:38:18 · 335 阅读 · 0 评论 -
PAT甲级 1032
1032. Sharing (25)To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same su原创 2017-07-22 13:00:28 · 250 阅读 · 0 评论 -
PAT甲级 1021 没有AC,留着重做
Deepest RootA graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. S原创 2017-07-09 14:33:59 · 460 阅读 · 0 评论 -
PAT甲级 1022
Digital LibraryA Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-原创 2017-07-13 15:10:53 · 504 阅读 · 0 评论 -
PAT甲级 1012
The Best RankTo evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra),原创 2017-06-24 17:15:34 · 669 阅读 · 0 评论 -
PAT甲级 1011
World Cup BettingWith the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in原创 2017-06-23 07:18:07 · 328 阅读 · 0 评论 -
PAT甲级 1010
RadixGiven a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is “yes”, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive原创 2017-06-22 13:44:23 · 607 阅读 · 0 评论 -
PAT甲级 1009
Product of PolynomialsThis time, you are supposed to find A*B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line con原创 2017-06-21 17:44:31 · 655 阅读 · 0 评论 -
PAT甲级 1017
Queueing at BankSuppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behin原创 2017-06-30 16:33:00 · 521 阅读 · 0 评论 -
PAT甲级 1016
Phone BillsA long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is ma原创 2017-06-29 19:02:35 · 515 阅读 · 0 评论 -
PAT甲级 1008
ElevatorThe highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It cost原创 2017-06-20 07:45:54 · 653 阅读 · 0 评论 -
PAT甲级 1015
Reversible PrimesA reversible prime in any number system is a prime whose “reverse” in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse原创 2017-06-28 19:29:09 · 427 阅读 · 0 评论 -
PAT甲级 1007
Maximum Subsequence SumGiven a sequence of K integers { N1, N2, …, NK }. A continuous subsequence is defined to be { Ni, Ni+1, …, Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous原创 2017-06-19 08:43:52 · 536 阅读 · 0 评论 -
PAT甲级 1006
Sign In and Sign OutAt the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing原创 2017-06-18 08:39:18 · 528 阅读 · 0 评论 -
PAT甲级 1005
Spell It RightGiven a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test原创 2017-06-17 08:11:13 · 549 阅读 · 0 评论 -
PAT甲级 1004
Counting LeavesA family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. InputEach input file contains one test case. Each case starts wi原创 2017-06-16 18:40:48 · 647 阅读 · 0 评论 -
PAT甲级 1013
Battle Over CitiesIt is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know imme原创 2017-06-25 18:17:08 · 374 阅读 · 0 评论 -
PAT甲级 1023
Have Fun with NumbersNotice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be anothe原创 2017-07-13 16:59:35 · 380 阅读 · 0 评论 -
PAT甲级 1024
Palindromic NumberA number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are pa原创 2017-07-13 19:18:43 · 414 阅读 · 0 评论 -
PAT甲级 1031
pat 1031Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, “helloworld” can be printed as:h de ll rlowoThat is, the characters must be原创 2017-07-20 22:09:18 · 512 阅读 · 0 评论 -
PAT甲级 1020
Tree TraversalsSuppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal seque原创 2017-07-08 05:22:56 · 479 阅读 · 0 评论