PAT
gq97
这个作者很懒,什么都没留下…
展开
-
PAT Advanced 1032 Sharing (25 )
PAT Advanced 1032 Sharing (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:11111 22222 967890 i 0...原创 2019-03-01 17:50:14 · 180 阅读 · 0 评论 -
PAT Top 1022 Werewolf (35)
PAT Top 1022 Werewolf (35)题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路从甲级过来的...原创 2019-02-17 22:47:10 · 1302 阅读 · 0 评论 -
PAT Advanced 1148 Werewolf - Simple Version (20)
PAT Advanced 1148 Werewolf - Simple Version (20)题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:Sampl...原创 2019-02-17 22:33:08 · 289 阅读 · 0 评论 -
PAT Advanced 1149 Dangerous Goods Packaging (25 )
PAT Advanced 1149 Dangerous Goods Packaging (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code总结题目描述Input Specification:Output Specification:Sample Input:Sa...原创 2019-02-17 21:08:06 · 215 阅读 · 0 评论 -
PAT Advanced 1150 Travelling Salesman Problem (25 )
PAT Advanced 1150 Travelling Salesman Problem (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code总结题目描述Input Specification:Output Specification:Sample Input:...原创 2019-02-17 20:20:57 · 339 阅读 · 0 评论 -
PAT Advanced 1153 Decode Registration Card of PAT (25 )
PAT Advanced 1153 Decode Registration Card of PAT (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code总结题目描述Input Specification:Output Specification:Sample Inpu...原创 2019-02-17 16:53:39 · 283 阅读 · 0 评论 -
PAT Advanced 1151 【LCA in a Binary Tree 】
PAT Advanced 1151 【LCA in a Binary Tree 】(30 分)题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述The lowest common ancestor (LCA) of two nodes U and V in a tree is...原创 2019-01-22 22:14:10 · 117 阅读 · 0 评论 -
PAT Advanced 1022 Digital Library(30 分)
分析:id用string会在最后一个点超时,看了柳神博客醒悟传参传引用(不用复制)能快不少,actually,在最后一个点上快了十倍的时间。#include<iostream>#include<cstdio>#include<map>#include<vector>#include<algorithm>using name...原创 2018-09-04 21:52:07 · 175 阅读 · 0 评论 -
PAT Advanced 1110 【Complete Binary Tree】(25)
分析:可由完全二叉树满足的编号关系入手,首先没出现在孩子的位置的结点是根节点,然后bfs进行遍历,对所有节点按完全二叉树进行编号,如根节点编号为0,其对应左孩子和右孩子的编号对应为0*2+1、0*2+2,即1和2。如果0到n之间有数字没被编号,则这不是一颗完全二叉树。#include<iostream>#include<cstdio>#include<que...原创 2018-08-25 22:55:25 · 150 阅读 · 0 评论 -
PAT Advanced 1109 【Group Photo】(25)
分析:快乐模拟。先按身高降序排序,再确定好每行元素之后,又给出了每一排的起始位置,然后向左向右安排,循环直到达到上界和下届为止。#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int maxn = 1e4+10;int group[12]...原创 2018-08-25 22:48:45 · 146 阅读 · 0 评论 -
PAT Advanced 1089 【Insert or Merge】(25)
分析:模拟归并排序和插入排序,并给出下一趟排序序列,注意归并排序的上限包括整个序列的长度。。#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int origin[110], cop[110], res[110], n, flag;int istheS...原创 2018-08-23 22:32:58 · 165 阅读 · 0 评论 -
PAT Advanced 1087 【All Roads Lead to Rome】 (30)
分析:利用map将string与int互相映射,再用Dijkstra+Dfs,注意路径不唯一的时候先取最大happiness,再取经过的城市更少的那条。#include<iostream>#include<cstdio>#include<algorithm>#include<vector>#include<map>#inc...原创 2018-08-23 22:22:15 · 185 阅读 · 0 评论 -
PAT Advanced 1086 【Tree Traversals Again】 (25)
分析:进栈的顺序便是先序遍历,出栈的顺序是中序遍历,由中序+先序即可求后序序列,由于题目说明了结点从1到N编号,因此无重复编号,可用下面做法:1. 先序:根左右2. 中序:左根右3. 后序:左右根先序的根找到对应中序的根的位置,再递归中序根左边的位置,根右边的位置,最后将根放进数组。当然也可以先建树再求后序遍历。#include<iostream>#incl...原创 2018-08-23 21:56:24 · 135 阅读 · 0 评论 -
PAT Advanced 1134 【Vertex Cover】(25)
分析:检查每一条边是否有已知顶点与之相连,如果无则输出No。#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn = 1e4+10;struct Edge{ int u, v;}e[maxn];int vis[maxn];...原创 2018-08-27 21:28:30 · 192 阅读 · 0 评论 -
PAT Advanced 1128 【N Queens Puzzle】(20 )
分析:检查N皇后满足没有任意两个皇后在同一对角线或者同一行。#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;const int maxn = 1e3+10;int queen[maxn];int judge(...原创 2018-08-27 21:22:29 · 149 阅读 · 0 评论 -
PAT Advanced 1066 【Root of AVL Tree】 (25)
分析:AVL树常规操作,靠着模糊的记忆和临时的推导把代码写了个大概,但是由于忘了要用引用将旋转后的结点返回导致没过样例,代码还是比较简洁的,可以作为AVL树的模板了。AVL树其实在理解了BST后就比较好理解和推导了,至于旋转过程自己在纸上也比较简单能推出。#include<iostream>#include<cstdio>#include<algorithm...原创 2018-08-20 16:50:12 · 159 阅读 · 0 评论 -
PAT Advanced 1122 【Hamiltonian Cycle】(25 分)
分析:哈密顿图需要满足以下条件:1. 首尾结点相等2. 结点总个数为n+13. 相邻节点是连通的4. 包含了所有节点#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn = 210;int e[maxn][maxn...原创 2018-08-27 11:25:26 · 152 阅读 · 0 评论 -
PAT Advanced 1034 Head of a Gang (30 )
PAT Advanced 1034 Head of a Gang (30 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:Sample Output:...原创 2019-02-27 21:25:46 · 244 阅读 · 0 评论 -
PAT Advanced 1063 Set Similarity (25 )
PAT Advanced 1063 Set Similarity (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:Sample Output:...原创 2019-02-27 21:29:43 · 190 阅读 · 0 评论 -
PAT Advanced 1067 Sort with Swap(0, i) (25 )
@[TOC](PAT Advanced 1067 Sort with Swap(0, i) (25 ))题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路一开始想复杂了以及循环处理不当导致两个测试点超时。。就是在for循环里面出现idx[i]!=i时,将idx[i]和idx...原创 2019-02-25 21:13:08 · 257 阅读 · 0 评论 -
PAT Advanced 1143 Lowest Common Ancestor (30 )
PAT Advanced 1143 Lowest Common Ancestor (30 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述The lowest common ancestor (LCA) of two nodes U and V in a tree is t...原创 2019-03-01 17:39:12 · 206 阅读 · 0 评论 -
PAT Advanced 1155 Heap Paths (30 )
PAT Advanced 1155 Heap Paths (30 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述In computer science, a heap is a specialized tree-based data structure that sati...原创 2019-03-01 17:17:32 · 268 阅读 · 0 评论 -
PAT Advanced 1154 Vertex Coloring (25 )
PAT Advanced 1154 Vertex Coloring (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述A proper vertex coloring is a labeling of the graph’s vertices with colors ...原创 2019-03-01 17:07:25 · 178 阅读 · 0 评论 -
PAT Advanced 1085 Perfect Sequence (25 )
PAT Advanced 1085 Perfect Sequence (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:Sample Output...原创 2019-02-25 18:48:28 · 124 阅读 · 0 评论 -
PAT Advanced 1100 Mars Numbers (20 )
PAT Advanced 1100 Mars Numbers (20 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:Sample Output:解...原创 2019-02-25 17:22:05 · 212 阅读 · 0 评论 -
层序和中序重建二叉树
层序和中序重建二叉树题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述输入一棵二叉树的层序和中序遍历,分别输出其前序和后序遍历Input Specification:第一行输入树的大小,接下来一行给出树的层序遍历,最后一行给出树的中序遍历。Output Specifica...原创 2019-03-01 12:19:49 · 1388 阅读 · 0 评论 -
PAT Advanced 1104 Sum of Number Segments (20 )
PAT Advanced 1104 Sum of Number Segments (20 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:Sample ...原创 2019-02-25 15:36:52 · 264 阅读 · 0 评论 -
PAT Advanced 1072 Gas Station (30 )
PAT Advanced 1072 Gas Station (30 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述A gas station has to be built at such a location that the minimum distance betw...原创 2019-02-28 22:14:03 · 193 阅读 · 0 评论 -
PAT Advanced 1129 Recommendation System (25 )
PAT Advanced 1129 Recommendation System (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code总结题目描述Input Specification:Output Specification:Sample Input:Sample...原创 2019-02-19 17:42:29 · 311 阅读 · 0 评论 -
PAT Advanced 1029 Median (25 )
PAT Advanced 1029 Median (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Given an increasing sequence S of N integers, the median is the number at the middl...原创 2019-02-28 20:15:44 · 134 阅读 · 0 评论 -
PAT Advanced 1131 Subway Map (30 )
PAT Advanced 1131 Subway Map (30 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code总结题目描述Input Specification:Output Specification:Sample Input:Sample Output:解...原创 2019-02-19 15:19:27 · 373 阅读 · 0 评论 -
PAT Advanced 1119 Pre- and Post-order Traversals (30 )
PAT Advanced 1119 Pre- and Post-order Traversals (30 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:...原创 2019-02-25 00:12:37 · 152 阅读 · 0 评论 -
PAT Advanced 1139 First Contact (30)
先挂题目链接~ 分析:u想追求v, 找出u的同性好朋友u1,v的同性好朋友v1,并且,u1和v1也得是好朋友。其中输入中带负号的为female。 注意点:不能用int定义输入数据,因为输入中含-0这种数据代表女生,用string存(被大神提醒)。每个人的id唯一,也就是不存在一个男生的id等于一个女生id的绝对值(暂时这么说),因此可以用她们的id进行存储。其他坑点,比如u的好友中有v,即u1...原创 2018-04-04 23:13:49 · 661 阅读 · 0 评论 -
PAT Advanced 1060 Are They Equal (25 )
PAT Advanced 1060 Are They Equal (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code题目描述Input Specification:Output Specification:Sample Input:Sample Output:...原创 2019-02-27 21:34:19 · 271 阅读 · 0 评论 -
PAT Advanced 1118 【Birds in Forest】(25 )
分析:PAT之日常并查集。#include<iostream>#include<cstdio>using namespace std;const int maxn = 1e4+10;int father[maxn], vis[maxn];int getF(int x){ return x == father[x] ? x : father[x] = get...原创 2018-08-27 10:09:41 · 109 阅读 · 0 评论 -
PAT Advanced 1115 【Counting Nodes in a BST】(30 )
分析:再树的存储里加上当前层数,建完树用dfs遍历即可。#include<iostream>#include<cstdio>using namespace std;struct Node{ int v, lev; struct Node *l, *r;};int maxlev, n1, n2;Node *insert(Node *root, int v...原创 2018-08-27 10:03:07 · 119 阅读 · 0 评论 -
PAT甲级1096 【Consecutive Factors】 (20)
Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given ...原创 2018-07-15 20:02:46 · 203 阅读 · 0 评论 -
PAT甲级1088 【Rational Arithmetic】 (20)
题目链接分析:分数的四则运算,模拟是最烦的,注意负号一直在分子位置处,输出负的假分数时,分子不用输出负号。#include<stdio.h>typedef long long ll;ll abs(ll a){ if(a < 0) return -a; return a;}ll gcd(ll a, ll b){ if(b == 0) return a; retur...原创 2018-07-15 11:45:48 · 208 阅读 · 0 评论 -
PAT甲级1056 【Mice and Rice】 (25)
模拟题,注意最后一组如果不满足比赛人数也要进行比赛,角逐出小组第一。另外比较头疼的是最后的排名。。我用了比较笨的方法。。。Object C#include&lt;stdio.h&gt;typedef struct Node{ int w; int idx; int rank;}Node;Node node[1010];int cmp(const voi...原创 2018-07-14 10:21:29 · 360 阅读 · 0 评论 -
PAT甲级1118 【Birds in Forest】
分析:PAT日常之并查集,递归findF返回是father[x]而不是x,注意最后的father[]数组不是最终每个结点的father,因此还要通过findF找其father,不过判断并查集个数可以直接用i == father[i]判断#include<stdio.h>int father[(int)1e4+7];void init(){ int i, len = (in...原创 2018-07-19 16:28:11 · 223 阅读 · 0 评论