
PAT (Advanced Level) Practise
文章平均质量分 79
Cassie曹
这个作者很懒,什么都没留下…
展开
-
1099. Build A Binary Search Tree (30)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key.The right原创 2016-06-01 12:13:38 · 235 阅读 · 0 评论 -
1080. Graduate Admission (30)
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admissio原创 2016-06-06 12:03:35 · 239 阅读 · 0 评论 -
1059. Prime Factors (25)
Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1 * p2^k2 *…*pm^km.Input Specification:Each input file contains one test c原创 2016-06-12 09:36:34 · 200 阅读 · 0 评论 -
1060. Are They Equal (25)
If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123*105 with simple chopping. Now given the number of significa原创 2016-06-12 10:54:12 · 264 阅读 · 0 评论 -
1030. Travel Plan (30)
IDEA1.求最短路径,并输出该路径2.要就在判断过程中若存在相同长度,则选cost小的3.Dijkstra改进CODE#include#include #include#includeusing namespace std;#define Max 500#define INF 0x6FFFFFFFstruct Edge{ int end; int原创 2016-06-28 10:54:03 · 422 阅读 · 0 评论 -
1057. Stack (30)
树状数组+二分法查找IDEA1.时间要求严格,不能普通的排序,然后输出2.不能用string,会超时,而且尽量使用scanf和printf,不要回cin和cout,这样更节省时间3.关于树状数组见分析http://blog.youkuaiyun.com/int64ago/article/details/7429868CODE#include#include#includ原创 2016-07-10 10:39:40 · 283 阅读 · 0 评论 -
1061. Dating (20)
Sherlock Holmes received a note with some strange strings: "Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm". It took him only a minute to figure out that those strange strings are a原创 2016-06-13 09:13:20 · 257 阅读 · 0 评论 -
1063. Set Similarity (25)
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of distinct num原创 2016-06-13 11:10:06 · 219 阅读 · 0 评论 -
1068. Find More Coins (30)
IDEA1.背包问题变形:原0-1背包问题是往背包转物品使其weight一定,总value最大;现在是使得value一定,最小的组合结果2.采用动态规划:f(n,m) = max{ f(n–1, m), f(n–1, m–value(n)) +value(n) },题中需要的结果是使得f(n,m)==给定的m3.用flag[][]来标记是否在达到某个阶段最大值的时候,用了某个value原创 2016-07-11 10:22:22 · 337 阅读 · 0 评论 -
1096. Consecutive Factors (20)
IDEA1.从2开始到n开方,作为连续因子的第一个进行检查2.环条件写i*iCODE#include#include#includeusing namespace std;int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif int n; cin>>n; int原创 2016-06-30 10:21:10 · 261 阅读 · 0 评论 -
1055. The World's Richest (25)
IDEA1.测试点二容易超时,所有的cin,cout该为scanf和printf;2.用scanf输入string类型#include #include using namespace std;int main(){ string a; a.resize(100); //需要预先分配空间 scanf("%s", &a[0]); puts(a.c_str()); ret原创 2016-06-27 09:31:04 · 422 阅读 · 0 评论 -
1097. Deduplication on a Linked List (25)
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or a原创 2016-06-05 12:17:23 · 209 阅读 · 0 评论 -
1042. Shuffling Machine (20)
Shuffling 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 collaborate with gambler原创 2016-04-24 20:16:11 · 199 阅读 · 0 评论 -
1014. Waiting in Line (30)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:The spa原创 2016-05-19 18:29:11 · 698 阅读 · 0 评论 -
1064. Complete Binary Search Tree (30)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key.The right原创 2016-06-01 22:21:54 · 284 阅读 · 0 评论 -
1086. Tree Traversals Again (25)
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac原创 2016-06-02 16:20:33 · 302 阅读 · 0 评论 -
1062. Talent and Virtue (25)
IDEA1.简单的结构体排序问题;2.注意用cin,cout作为输入输出会超时,要改用scanf,printf;CODE#include#include#include #include#include#includeusing namespace std;struct Person{ //string id; int id; int virtue;原创 2016-06-23 23:04:29 · 221 阅读 · 0 评论 -
1056. Mice and Rice (25)
IDEA1.需要vector:programer,order,used(初始化为0),used值为1的不进入下一轮2.计算分组数:np%ng==0?group=np/ng:group=np/ng+1; 以group为循环依据group%ng==0?group=group/ng:group=group/ng+1;group==1则下一次不在循环3.计算每组的最大值,记录其id,并给原创 2016-06-24 10:54:28 · 253 阅读 · 0 评论 -
1043. Is It a Binary Search Tree (25)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key.The right原创 2016-06-02 23:03:24 · 228 阅读 · 0 评论 -
1047. Student List for Course (25)
Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.Input S原创 2016-06-03 10:34:06 · 249 阅读 · 0 评论 -
1085. Perfect Sequence (25)
Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M Now given a sequence and a parameter p, you are supposed to find from the原创 2016-06-04 11:02:23 · 231 阅读 · 0 评论 -
1065. A+B and C (64bit) (20)
Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.Input Specification:The first line of the input gives the positive number of test cases, T (Output原创 2016-06-15 09:32:33 · 218 阅读 · 0 评论 -
1016. Phone Bills (25)
IDEA1.主要思想:将对有记录按姓名-时间顺序排序,然后过滤不合法记录,最后最近收费2.算时间差方法:算出每个人的总时间,然后相减3.用printf输出string字符串,str.c_str()文章参考别人的 http://blog.youkuaiyun.com/sunbaigui/article/details/8657062CODE#include#inclu原创 2016-07-24 11:11:50 · 467 阅读 · 0 评论 -
1053. Path of Equal Weight (30)
IDEA1.树的存储 vector > vec2.树的深度遍历DFS,输出遍历路径3.vector的方法,back()返回最末元素pop_back()移除最后一个元素CODE#include#include #include#includeusing namespace std;#define Max 110int s;int weight[Max];原创 2016-06-21 10:47:02 · 412 阅读 · 0 评论 -
1069. The Black Hole of Numbers (20)
IDEA1.输入的正整数在(0-10000),如果输入小于4位,则补零补齐4位,在哪个位置没有关系,反正需要排序2.如果结果为0000或者6174,则循环继续 CODE#include#include#include#include#includeusing namespace std;int cmp1(int a,int b){ return a>b;//降原创 2016-06-22 11:25:15 · 253 阅读 · 0 评论 -
1070. Mooncake (25)
IDEA1.首先n和d为正整数,分别表示月饼数和需求量;第二行是每种月饼的库存,为正数,不一定是正数,用float型;2.可能存在总库存小于需求d的情况CODE#include#include #include#include#includeusing namespace std;#define Max 1001struct Cake{ float nu原创 2016-06-22 12:01:25 · 228 阅读 · 0 评论 -
1071. Speech Patterns (25)
IDEA1.isalnum()判断是否为字母或者数字2.stringsteam ss; ssword=ss.str();//将缓冲流ss中的字符串写入到word中 ss.str("");清空缓冲流中内容3.transform(first,last,result,op);CODE#include#include#include #include#include原创 2016-06-22 16:05:28 · 223 阅读 · 0 评论 -
1046. Shortest Distance (20)
IDEA:求圆环中两点距离最短1.时间限制是考查点;2.在输入两点之间距离的同时,计算每个点到点1 的距离3.计算两点间的最短距离,正向(或反向)的大个最短,如圆环总长-正向距离=反向距离。CODE#include#include#include#includeusing namespace std;int main(){ #ifndef ONLINE原创 2016-07-08 10:04:31 · 237 阅读 · 0 评论 -
1093. Count PAT's (25)
IDEA:1.需要从后往前遍历字符串,统计T的个数,AT的个数,PAT的个数,排列组合问题2.碰到T,记录该T后面T的总个数(包括这个T);碰到A,记录该A后面AT组合的总个数;其中包括之前统计的A后面AT的总个数加上这个A与后面全部T组合的个数(即之前统计的T的总个数);碰到P,记录该P后面PAT组合的总个数。CODE#include#include#原创 2016-07-08 10:32:48 · 256 阅读 · 0 评论 -
1039. Course List for Student (25)
IDEA1.很自然的思路是设计map > record; 但是由于string的各种操作,使得最后一个case超时;2.我们观察到文中描述name右3个大写字母和一位数字组成,即最多有MAX=26*26*26*10个学生。需要做name到数字id之间的映射,id=(name[0]-'A')*26*26*10+(name[1]-'A')*26*10+(name[2]-'A')*10+na原创 2016-07-09 10:17:57 · 565 阅读 · 0 评论 -
1048. Find Coins (25)
IDEA1.注意题目给的数字范围的大小,m2.从1-m/2遍历即可,不用遍历到mCODE#include#include #includeusing namespace std;#define MAX 1001int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif原创 2016-08-28 09:32:27 · 349 阅读 · 0 评论 -
1045. Favorite Color Stripe (3
IDEA1.本题是求最长连续子串,但是相同子串允许重复出现2.采用动态规划方法,将动态表表示最大出现长度 224155631156 00000000000原创 2016-08-29 10:13:11 · 548 阅读 · 0 评论 -
1052. Linked List Sorting (25)
IDEA1.如果start address==-1,则直接输出 0 -1,不用再执行下面操作,如果执行了会数组越界CODE#include#include#include #include #include#includeusing namespace std;#define Max 100000struct Node{ int add; int key;原创 2016-06-20 22:19:10 · 196 阅读 · 0 评论 -
1078. Hashing (25)
IDEA1.二次探测法: hi=(h(key)+i*i)%m 0≤i≤m-1,即即探查序列为d=h(key),d+1^2,d+2^2,…2.判断是否为素数CODE#include#include #include#include#includeusing namespace std;#define Max 10010int table[Max],tsize;原创 2016-06-20 10:45:22 · 200 阅读 · 0 评论 -
1077. Kuchiguse (20)
The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called原创 2016-06-16 09:45:40 · 192 阅读 · 0 评论 -
1076. Forwards on Weibo (30)
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a原创 2016-06-16 10:58:11 · 245 阅读 · 0 评论 -
Sort with Swap(0,*) (25)
IDEA1.注意输入的数字从0-n-1,意思是让数字存在其对应下标下2.题目只让0和某数交换,交换次数尽量少,则尽量让该数放在正确位置下,完后就不参与交换了3.考虑两种情况:array[0]==0,0本身在正确位置,若还有不在正确位置的数字,则0与其交换;array[0]!=0,让通过交换使得array[0]到正确位置,指导位置0有正确数,即0.位置;然后重复第一种情况原创 2016-07-25 11:24:07 · 219 阅读 · 0 评论 -
1073. Scientific Notation (20)
Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9]"."[0-9]+E[+-][0-9]+ which means that the in原创 2016-06-17 10:01:37 · 278 阅读 · 0 评论 -
1095. Cars on Campus (30)
看了几个别人写的,感觉这个还不错http://blog.youkuaiyun.com/xyt8023y/article/details/48029443写一次理解:1.首先把这N条记录存储起来,按时间从小到大排序,时间统计转换为秒2.遍历该N条记录,存放到map中,有in,有out,且inTime总停车时间(同一个车可能同时进出多次)3.按时间从小到大的顺便排序2中存的有效记录,截止到转载 2016-07-03 10:55:12 · 257 阅读 · 0 评论 -
1044. Shopping in Mars (25)
IDEA1.主要思想是将diamond的值累加,形成从小到大的有序序列,用二分法查找,满足>=m的最小序列2.从1-n重复查找,找出最小的满足情况的序列(多个)CODE#include#include#includeusing namespace std;//二分法查找 void find(vector &val,int m,int begin,int &end,原创 2016-07-26 09:59:58 · 255 阅读 · 0 评论