
PAT甲级
god_speed丶
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
1082 Read Number in Chinese (25 分)
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai ...原创 2019-02-24 14:12:02 · 344 阅读 · 0 评论 -
1108 Finding Average(20 分)
1108 Finding Average(20 分) The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be le...原创 2018-08-26 11:33:50 · 574 阅读 · 0 评论 -
1032 Sharing (25)(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 suffix. For example,...原创 2018-07-07 00:28:11 · 905 阅读 · 4 评论 -
PAT1045. Favorite Color Stripe (30)
这道题可以抽象为最长不递减子串 给定 5 4 3 2 1 一个序列 — 3 4 5 1 2 2 对应的index 3 2 1 5 4 4 看可以发现1 4 4(对应5 2 2)满足题目要求 求这样的子串有O(NlogN)的算法 我叫他为贪吃蛇法 百度最长上升子序列NLOGN法#include <bits/stdc++.h>using namespac...原创 2018-07-06 16:35:39 · 131 阅读 · 0 评论 -
1052 Linked List Sorting (25)(25 分)
A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now give...原创 2018-07-06 15:43:32 · 344 阅读 · 0 评论 -
1068 Find More Coins (30)(30 分)
1068 Find More Coins (30)(30 分) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kin...原创 2018-07-06 09:22:13 · 707 阅读 · 0 评论 -
1077 Kuchiguse (20)(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 ...原创 2018-07-06 00:07:52 · 807 阅读 · 0 评论 -
1087 All Roads Lead to Rome (30)(30 分)
dijkstra模板题 问题的关键在于不同情况的判断 相等的时候会改变哪些值 最短的时候更新哪些值 代码量基本90-150行了很难优化 见注释#include <bits/stdc++.h>using namespace std;#define MAXN 0X3F3F3F3Fint graph[500][500];map<string, int> ha...原创 2018-07-05 00:08:07 · 522 阅读 · 0 评论 -
1018. Public Bike Management (30)
最短路+dfs 好难啊~~~ 用dijkstra找到所有的最短路路径并记录下来 用dfs找到最短路径中最合适的那一条 这两种的结合的方式要牢牢掌握~找到后输出即可 dfs 模拟车的搬运 很巧妙#include <bits/stdc++.h>using namespace std;int graph[1000][1000];#define MAXN 0x3f3f3f3...原创 2018-07-10 19:08:56 · 167 阅读 · 0 评论 -
1118 Birds in Forest(25 分)
并查集入门,关键是想到并查集,我还想了其他操作好久发现没有什么想法 一个合并一个查找,就该想到并查集嘛 对于每一棵树上的鸟,可以将第一只作为已知在树上的鸟,把后面的鸟捉过来即可#include <bits/stdc++.h>using namespace std;int fa[102000];int find(int x){ return fa[x]==x?x:f...原创 2018-08-26 17:06:16 · 703 阅读 · 0 评论 -
1101 Quick Sort(25 分)
题意很简单,大力枚举显然不行O(n^2) 可以首先从前往后扫一遍记录最大值,开一个数组记录一下 从后扫一遍记录最小值 O(n) 最后一句代码是本题的坑点#include <bits/stdc++.h>using namespace std;int a[102000];bool b[102000];bool c[102000];int main(){ int...原创 2018-08-23 21:17:09 · 915 阅读 · 0 评论 -
1105. Spiral Matrix (25)
思想:乱搞,排序,模拟 刚开始以为一个数开根号取整就行了,忽略了一些极端情况 如5=5*1 因此可以大力枚举,也可以在根号附近找值 可能的样例: 5 1 2 3 4 5out: 5 4 3 2 1难点在于while的使用和判断什么时候填与不填 可以判断矩阵的元素是否为0,不为0显然不能填 四个循环的写法很巧妙,可以借鉴一下,++的妙用,可以让程序变得很简洁#i...原创 2018-08-23 22:33:03 · 142 阅读 · 0 评论 -
PAT_考试技巧
1.坑点:爆int,请用long long 如1104 Sum of Number Segments(20 分)原创 2018-09-10 21:14:12 · 3163 阅读 · 0 评论 -
1139 First Contact(30 分)
1139 First Contact(30 分) Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle in the early years. When a boy A had a crush on a girl B, he would usually ...原创 2018-09-06 21:02:13 · 485 阅读 · 0 评论 -
PAT (Advanced Level) Practice
套路题 并查集合并+统计出答案#include <bits/stdc++.h>using namespace std;#define FORP(i,a,b) for(int i=(a);i<=(b);i++)#define mp(a,b) make_pair(a,b)#define db(a) (cout<<"----"<<a<<e...原创 2018-09-06 19:29:03 · 169 阅读 · 0 评论 -
1143 Lowest Common Ancestor(30 分)
常规解法,建树 中序遍历=升序排序 以为数据水写了好多map没卡过去(大概单次nlognlogn) 换了别的方法查找lca 这样查找为log级别#include <bits/stdc++.h>using namespace std;#define FORP(i,a,b) for(int i=(a);i<=(b);i++)#define db(a) (cout<...原创 2018-09-06 10:33:55 · 154 阅读 · 0 评论 -
1072 Gas Station(30 分)
1072 Gas Station(30 分) A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must gu...原创 2018-09-03 20:55:21 · 581 阅读 · 0 评论 -
1145 Hashing - Average Search Time(25 分)
奇怪的题目 没找到次数要+1?????? 搜了很多资料没有对此的解释 本体正确性存疑#include <bits/stdc++.h>using namespace std;#define FORP(i,a,b) for(int i=a;i<=b;i++)#define db(a) (cout<<"---"<<a<<endl)#...原创 2018-09-05 20:08:53 · 493 阅读 · 2 评论 -
1111. Online Map (30)
码量充足 题意明确 dfs+spfa解法#include <bits/stdc++.h>using namespace std;#define FORP(i,a,b) for(int i=a;i<=b;i++)#define db(a) (cout<<"---"<<a<<endl)#define mp(a,b) make_pair...原创 2018-09-05 14:41:53 · 723 阅读 · 0 评论 -
1107. Social Clusters
有共同爱好的属于一个集合 并查集! 注意可以先合并再查每个人属于哪个集合#include <bits/stdc++.h>using namespace std;#define FORP(i,a,b) for(int i=a;i<=b;i++)set<int> s[1025];int fa[1024];int cnt[1024];int find(i...原创 2018-09-05 10:39:35 · 196 阅读 · 0 评论 -
【PAT】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 su...原创 2018-07-03 22:08:04 · 211 阅读 · 0 评论 -
1017. Queueing at Bank (25)
模拟题做吐 根据来得时间分配窗口,timeBase记录当前窗口开放的时间,即顾客离开的那一时刻 判断顾客来银行的时间和timeBase的大小 确定哪一方来得早 来得早就会产生等待时间 来得晚直接就接客了~ 注意处理的时间是min为单位 记得转换成秒#include <bits/stdc++.h>using namespace std;struct node{ ...原创 2018-07-10 15:10:46 · 181 阅读 · 1 评论 -
1016. Phone Bills (25)
繁琐的模拟题系列 ~~~ 1.判断on 与 off 的有效性 2.on后紧跟off才算一对 3.话费的计算 02:30 -03:37 相当于2*60+30 - (3*60+37-1) sum(150~216) 只要知道每个点的花费 可以O(n)计算 有的解法计算了小时 复杂度更优 我个人喜欢自己这种方法 比较直观 4.格式的输出不解释了吧 注意小数点和换行 5.模拟题考的是...原创 2018-07-10 13:35:47 · 160 阅读 · 0 评论 -
1082. Read Number in Chinese (25)
1.非常好的一道模拟题 2.所谓模拟题就是根据题意写程序,许多模拟题都会有一堆if else 3.能否简化就在于如何在短时间内对题目有一个深入的理解1082. Read Number in Chinese (25)时间限制 400 ms内存限制 65536 kB代码长度限制 16000 B判题程序 Standard 作者 CHEN, YueGiven an int...原创 2018-05-01 18:53:55 · 240 阅读 · 0 评论 -
1044. Shopping in Mars (25)
非常好的一道模拟题 刚开始题目愣是没看懂 其实搞明白写出来很快的 刚好能支付的,记录下来! 有零钱找的 要调那种给出租车司机钱最少的,但够数,而且是多给的 开两个vector记录多给的start和end,不断找,更新多给的钱,一有能少给点的就清空之前所有的值并记录下来 比如比如 5 13 2 4 5 7 9 第一步 2 <13 给钱太少 第二步 6 <13 给钱太...原创 2018-04-06 16:47:32 · 485 阅读 · 0 评论 -
1025. PAT Ranking (25)
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists w...原创 2018-04-06 08:45:17 · 161 阅读 · 0 评论 -
1051. Pop Sequence (25)
模拟入栈出栈 根据样例编写程序#include <cstdio>#include <iostream>#include <stack>using namespace std;int main(){ int m,n,k; scanf("%d %d %d",&m,&n,&k); for(int i=0;i...原创 2018-04-09 17:26:41 · 111 阅读 · 0 评论 -
03-树3 Tree Traversals Again(25 分)
PUSH操作可以得到前序遍历的结果 1 2 3 4 5 6 POP操作可以得到中序遍历的结果 3 2 4 1 6 5 题目化简为已知前序遍历和中序遍历,如何求得后序遍历 前序遍历:根左右 中序遍历:左根右 后序遍历:左右根 可以发现,根的位置决定了他属于什么序列回到题目中来,该如何求得后序遍历的具体数值呢??????前序遍历的第一个,是根,他应该被放在后序遍历的最后一...原创 2018-03-23 12:22:23 · 655 阅读 · 0 评论 -
1038. Recover the Smallest Number (30)
好题!!刚开始一直没想到合适的算法,想着一个数字一个数字比较,放弃!网上看了思路,发现很好 比如 29 32 2932&3229 1 27 271&127 更多一点 32 321 3214 -》直接看结果!!!321 3214 32 任意两个数交换都不会产生更大的数 那么好我们的解法就是让数排个序,其中任意两个相连的交换之后都没法比我们要的结果大!! 一个sort搞定...原创 2018-03-22 23:48:13 · 136 阅读 · 0 评论 -
1010 RADIX
Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answe...原创 2018-03-18 17:01:30 · 158 阅读 · 0 评论 -
1007. Maximum Subsequence Sum (25)
很好的题目,注意复杂度!! 参考点: 4 2 9 0 85 -5 0 0 -53 -2 -3 1#include <stdio.h>int main(){ int t; scanf("%d",&t); int num; int start=0; int end=0; int flag=0; int ...原创 2018-03-18 09:43:26 · 137 阅读 · 0 评论 -
1063. Set Similarity (25)
map有个陷阱 下标[key]方法:若插入元素的键值已经存在于map中,那么会更新该键值对应的值为新的元素的值;若该键值在map中找不到,那么就会新建一个键值为该键(key)的元素,并将key对应的值赋值为默认值(默认构造函数生成的对象)。我刚开始使用mymap[temp]>0来当做判断条件,竟然影响了后面的结果。。。注意啊#include <bits/stdc++.h>...原创 2018-05-01 22:08:34 · 112 阅读 · 0 评论 -
1090. Highest Price in Supply Chain (25)
1.题目梗概:给定供应商,算价格 2.可以先画个图,题目要求输出的是价格最高的,以及最高的数量 3.转换为求深度 4.我使用了记忆化搜索的方法,递归过程中对每个已知的值保存下来,不必采用大量的递归,需要用到的话直接加上去就可以了#include <bits/stdc++.h>using namespace std;int emm[100004]={0};int leve...原创 2018-04-25 22:28:01 · 127 阅读 · 0 评论 -
PAT 1020 Tree Traversal
转自:与后序中序转换为前序的代码相仿(无须构造二叉树再进行广度优先搜索~~),只不过加一个变量index,表示当前的根结点在二叉树中所对应的下标(从0开始),所以进行一次输出先序的递归的时候,就可以把根结点下标所对应的值存储在level数组中(一开始把level都置为-1表示此处没有结点),这样在递归完成后level数组中非-1的数就是按照下标排列的层序遍历的顺序#include <bi...转载 2018-04-26 13:57:55 · 208 阅读 · 0 评论 -
1046 Shortest Distance (20)(20 分)
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits. Input Specification: Each input file conta...原创 2018-06-28 10:49:30 · 1035 阅读 · 0 评论 -
PAT 1013
1013 Battle Over Cities (25)(25 分) It 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...原创 2018-06-27 22:06:26 · 289 阅读 · 0 评论 -
PAT1014 Waiting in Line (30)
1014 Waiting in Line (30)(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 customer...原创 2018-07-10 00:31:37 · 199 阅读 · 0 评论 -
PAT1022
考察map的使用,map的遍历 嵌套vector 和 getline()函数 注意这玩意遇到回车停止#include <bits/stdc++.h>using namespace std;map<string, vector<string> > book[10];map<string, vector<string> >::...转载 2018-06-26 15:28:45 · 272 阅读 · 0 评论 -
1021 Deepest Root (25)(25 分)
1021 Deepest Root (25)(25 分) A 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 i...原创 2018-06-29 17:37:44 · 2288 阅读 · 6 评论 -
1056 Mice and Rice (25)(25 分)
Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice...原创 2018-06-29 11:42:00 · 599 阅读 · 0 评论