PAT甲级:1066 Root of AVL Tree (25分) 题干 An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to rest…
1002 A+B for Polynomials (25 分) This 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 contains the information of a polynomial…
1079 Total Sales of Supply Chain (25 分)   A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain b…
1067 Sort with Swap(0, i) (25 分)   Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may…
题意: 输入一个正整数N(<=10),接着输入0~N-1每个结点的左右儿子结点,输出这颗二叉树的反转的层次遍历和中序遍历. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ][]; ]; void bfs(int r){ queue<int>q; q.push(r); cout<<r; while(!q.empty()){ in…
题意: 输入一个正整数N(<=100),接着输入两行N个数,表示原数组和经过一定次数排序后的数组.判断是经过插入排序还是堆排序并输出再次经过该排序后的数组(数据保证答案唯一). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],b[]; ][]; int main(){ ios::sync_with_stdio(false); cin.tie(NUL…
题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]={"","yi","er","san",&qu…
题意: 输入一个正整数N(<=20),接着输入N个结点的值,依次插入一颗AVL树,输出最终根结点的值. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; typedef struct node{ int val; node*left,*right; }; node*left_rotate(node*root){ node*tamp=root->…
题意: 输入两个正整数N和K(N<=1e5,K<=1000),接着输入N行,每行包括一位老板的名字,年龄和财富.K次询问,每次输入三个正整数M,L,R(M<=100,L,R<=200),输出至多M位年龄区间在L,R之间的老板的名字年龄和财富,按照财富降序,年龄升序,姓名字典序输出. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; st…
题意: 输入两个正整数N和K(N<=40000,K<=2500),接下来输入N行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号.输出每门课程有多少学生选择并按字典序输出学生的名字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; vector<]; int main(){ ios::sync_with_stdio…
题意: 输入两个正整数N和K(N<=40000,K<=2500),分别为学生和课程的数量.接下来输入K门课的信息,先输入每门课的ID再输入有多少学生选了这门课,接下来输入学生们的ID.最后N次询问,输入学生的ID输出该学生选了多少们课,输出所选课程的数量,按照递增序输出课程的ID. trick: 第5个数据点出现段错误,把原本以map存学生对应ID再映射vector存储该学生所选课程改成vector嵌套在map内,就没有段错误的问题出现,疑似映射过程中指针漂移??? AAAAAccepted…
题意:给出两个多项式,计算两个多项式的和,并以指数从大到小输出多项式的指数个数,指数和系数. AAAAAccepted code: #include<bits/stdc++.h> using namespace std; ]; int main(){ int k; cin>>k; ; ;i<=k;++i){ int n; cin>>n; double x; cin>>x; a[n]+=x; max_n=max(max_n,n); } cin>&g…
PAT甲级:1124 Raffle for Weibo Followers (20分) 题干 John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo -- that is, he would select winners from every N followers who forwarded his post, and give aw…
PAT甲级: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 subtre…
1006 Sign In and Sign Out (25)(25 分) At 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 in's and out's, you are supposed…
PATA1006 Sign In and Sign Out At 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 in's and out's, you are supposed to fin…
https://pintia.cn/problem-sets/994805342720868352/problems/994805516654460928 At 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…
题目分析:由于不存在相同的两个时间(24:00:00和00:00:00不会同时存在),则我们假设两个全局变量存放到达的最早的时间和达到的最晚的时间,设置最早的初值为“23:59:59”,设置最晚的初值为“00:00:00”,只要一个人到达的时间比最早的早则更新最早时间同时将id记录下来,最晚的情况也是同样的 #include<iostream> #include<string> using namespace std; int main(){ int n; while(scanf(…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6803291.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 题意:给你一个插入的序列,问你最后AVL树的根节点是多少 AVL树模板题如果会AVL树,那么就是水题如果不会的话,那么就是难题我刚开始也不会,所以根本写不出来AVL树...后来花了一些时间学习了下,感觉网上很多模板都是用class写的,太麻烦了模板就是应该要…
1011 World Cup Betting (20)(20 分)提问 With 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 South Africa. Similarly, footb…
1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Each input file contains one test case. Each case…
一开始是建立了course[2501][40001]数组,存储每节课的学生编号然后for循环两层输出,但这样复杂度为O(2500*40000),也很明显导致最后时间超时后来发现最多40000学生,每个学生最多选20门课,那么总共也就40000*20所以直接就存储学生-课程的信息,然后排个序,按照课程从小到大,课程一样的话则按字典序然后从头扫一遍即可,复杂度O(80000)不过要注意一点,有些课可能并没有出现,所以要做个判断,输出x 0. #include <iostream> #include…
1011 World Cup Betting (20)(20 分) With 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 South Africa. Similarly, footbal…
1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the seco…
1065 A+B and C (64bit) (20 分)   Given three integers A, B and C in [−], 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 (≤). Then T test cases follow, each consists o…
让我们用字母 B 来表示“百”.字母 S 表示“十”,用 12...n 来表示不为零的个位数字 n(<),换个格式来输出任一个不超过 3 位的正整数.例如 234 应该被输出为 BBSSS1234,因为它有 2 个“百”.3 个“十”.以及个位的 4. 输入格式: 每个测试输入包含 1 个测试用例,给出正整数 n(<). 输出格式: 每个测试用例的输出占一行,用规定的格式输出 n. 输入样例 1: 234 输出样例 1: BBSSS1234 输入样例 2: 23 输出样例 2: SS123 #…
Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the values in [0, K] appear before all those greater than K. The order of the elements inside each…
题意:输入一个正整数N(<=1e5),接着输入N个小于等于1.0的正数,输出N个数中所有序列的和. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; int main(){ //ios::sync_with_stdio(false); //cin.tie(NULL); //cout.tie(NULL); int n; scanf("%d&…
题意:输入一个正整数N(<=1000),接着输入N个非负整数(<=2000),输出完全二叉树的层次遍历. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; int cnt; int n; void dfs(int x){ if(x>n) return; dfs(x*); tree[x]=a[++cnt]; dfs(x*+); }…
题意: 输入两组,每组三个非负整数A,B,C(A<=1e7,B<17,C<29),输出相加的和.(类似个位上29进制,十位上17进制运算) AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a…