PAT(Advanced Level)
文章平均质量分 61
十觞亦不醉
编程浪子
展开
-
1001. A+B Format (20)
#include #include #include using namespace std;string toString(int num){ if(num == 0) return string("0"); string s; int flag = 0; while(num){ s = char(num % 10 + '0') +原创 2016-01-16 17:55:06 · 322 阅读 · 0 评论 -
1002. A+B for Polynomials (25)
#include #include #include using namespace std;int main(){ std::vector coef(1001, 0); for(int i = 0; i < 2; ++i){ int k, exp; float c; scanf("%d", &k); for (int j = 0; j < k; ++j){原创 2016-01-16 17:56:23 · 246 阅读 · 0 评论 -
1005. Spell It Right (20)
Given 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 case. Eac原创 2016-01-19 16:30:09 · 321 阅读 · 0 评论 -
1006. Sign In and Sign Out (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原创 2016-01-19 16:31:51 · 334 阅读 · 0 评论 -
1008. Elevator (20)
The 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 costs 6 sec原创 2016-01-19 16:43:29 · 263 阅读 · 0 评论 -
1083. List Grades (25)
Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades原创 2016-01-22 18:30:36 · 653 阅读 · 0 评论 -
1084. Broken Keyboard (20)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to原创 2016-01-23 19:37:25 · 203 阅读 · 0 评论 -
1023. Have Fun with Numbers (20)
Notice 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 another 9-digit number con原创 2016-01-23 20:09:21 · 248 阅读 · 0 评论 -
1081. Rational Sum (20)
Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with a positive i原创 2016-01-23 23:55:22 · 253 阅读 · 0 评论 -
1057. Stack (30)
一、题目Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top positi原创 2016-01-24 13:05:16 · 285 阅读 · 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原创 2016-01-24 22:58:34 · 327 阅读 · 0 评论 -
1007. Maximum Subsequence Sum (25)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. TheMaximum Subsequence is the continuous subsequence which原创 2016-01-25 10:57:23 · 255 阅读 · 0 评论 -
1009. Product of 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 informa原创 2016-01-25 11:22:21 · 266 阅读 · 0 评论 -
1011. World Cup Betting (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. Si原创 2016-02-05 21:26:07 · 211 阅读 · 0 评论 -
1012. The Best Rank (25)
To 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), and E - Eng原创 2016-02-06 12:03:36 · 232 阅读 · 0 评论 -
1085. Perfect Sequence (25)
排序后贪心#include #include #include #include using namespace std;int main(){ int n, p; scanf("%d%d", &n, &p); vector arr(n); for(int i = 0; i < n; ++i){ scanf("%lld", &arr[i]); } sort原创 2016-03-01 11:28:07 · 289 阅读 · 0 评论 -
1086. Tree Traversals Again (25)
所有的Push组成前序遍历,pop出来的顺序为中序遍历,转化为知道前序与中序,求后序遍历的问题#include #include #include #include using namespace std;struct Node{ int val; Node* left; Node* right; Node(int v) : val(v), left(nullptr原创 2016-03-02 22:02:27 · 322 阅读 · 0 评论 -
1087. All Roads Lead to Rome (30)
DFS, 走的过程,把符合条件的全记录下来#include #include #include #include using namespace std;#define MAX_CITY (205)#define INF (~(1<<31))vector> graph(MAX_CITY, vector(MAX_CITY, -1));vector happy(MAX_C原创 2016-03-02 23:12:04 · 1137 阅读 · 2 评论 -
1088. Rational Arithmetic (20)
给定分子分母能准确给出其标准形式,期间需要求最大公约数,注意负数还有加括号的处理#include #include #include using namespace std;long long gcd(long long a, long long b){ while(b){ long long r = a%b; a = b; b = r; } return原创 2016-03-03 08:48:09 · 571 阅读 · 0 评论 -
1089. Insert or Merge (25)
判断是否为插入排序较为简单,只需找到第一个违反升序的数,判断从该数开始,其后所有的数是否与原数组一样,是则采用的插入排序,否则采用的归并排序。对于归并排序,关键是找到当前几个元素一组,然后进行下一次归并即可。#include #include #include #include using namespace std;bool isequal(vector& arr, vec原创 2016-03-03 14:36:08 · 1013 阅读 · 1 评论 -
1090. Highest Price in Supply Chain (25)
DFS走一遍,找出最大深度,如果最大深度的叶结点不止一个,则统计数量。#include #include #include #include using namespace std;vector> chains;int maxLevel = 0;int maxNum = 0;void dfs(int src, int level){ if(chains[src].e原创 2016-03-03 14:57:28 · 699 阅读 · 0 评论 -
1091. Acute Stroke (30)
主要在于理解题意,读了三遍,竟然没懂啥意思,最后还看了Uncle_Sugar 的解释才明白,真是给这题跪了。实质上是三维空间走一遍DFS或者BFS,统计一下连通区域中1的个数,其中如果一个连通区域1的个数小于给定阈值则不算进去。#include #include #include #include using namespace std;int graph[1286][1原创 2016-03-03 16:17:02 · 357 阅读 · 0 评论 -
1092. To Buy or Not to Buy (20)
直接建表查询#include #include #include #include using namespace std;int main(){ string owner, eva; cin >> owner >> eva; unordered_map table; for(auto& c : owner){ if(table.find(c) == table原创 2016-03-03 16:32:14 · 437 阅读 · 0 评论 -
1093. Count PAT's (25)
线性走一遍,如果遇到P则把当前位置之前P的个数加1,遇到A则更新当前位置之前 PA 的个数,遇到 T 则统计PAT的个数#include #include using namespace std;int main(){ string s; cin >> s; const int N = 1000000007; long long sum = 0; int p = 0,原创 2016-03-03 17:08:21 · 255 阅读 · 0 评论 -
1094. The Largest Generation (25)
走一遍BFS,计算每一层的孩子数目,同时跟踪最大值#include #include #include #include using namespace std;vector> tree;int main(){ int n,m; scanf("%d%d", &n, &m); tree.resize(n+1, vector()); for(int i = 0; i原创 2016-03-03 17:22:35 · 356 阅读 · 0 评论 -
1095. Cars on Campus (30)
考查结构体排序,需要足够细心,大致思路是先将所有记录按车牌号排序,车牌号一样按时间排序,然后将合法的记录挑选出来。在查询的时候,维护当前已经查询到何处,下一次查询从当前位置开始。查询中,如果是进的,则把当前车辆数加1,出的则减1,同时更新车辆所停靠的时间,顺便选出最长停靠时间及相关车辆。#include #include #include #include #include #i原创 2016-03-03 21:24:39 · 334 阅读 · 0 评论 -
1096. Consecutive Factors (20)
一开始思路错了,参考了这里的解法。#include #include #include using namespace std;int main(){ int n; scanf("%d", &n); pair p; int len = 0; int r = sqrt(n); for(int i = 2; i <= r; ++i){ int j = i;原创 2016-03-03 22:08:04 · 256 阅读 · 0 评论 -
1097. Deduplication on a Linked List (25)
先走一遍,找出所有有效的链表节点,然后按要求将节点分成两组,然后输出#include #include #include #include #include using namespace std;struct Node{ int add, key, next; Node(){} Node(int a, int k, int n) : add(a), key(k),原创 2016-03-03 22:54:03 · 347 阅读 · 0 评论 -
1098. Insertion or Heap Sort (25)
先判断是否为插入排序,不是的话找出堆排序进行到第几次,然后再来一次。#include #include #include #include using namespace std;int main(){ int n; scanf("%d", &n); vector arr(n), part(n); for(int i = 0; i < n; ++i){ sca原创 2016-03-04 10:09:34 · 377 阅读 · 0 评论 -
1003. Emergency (25)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the l原创 2016-02-18 09:50:59 · 630 阅读 · 0 评论 -
1099. Build A Binary Search Tree (30)
从根结点开始,每次统计根节点左边孩子节点的数目n,以此确定当前根节点的key值,应该是所有的key排序之后的数组的第n+1个值,递归构建即可。#include #include #include #include #include using namespace std;struct Node{ int key, left, right; Node(){} Node原创 2016-03-04 10:45:41 · 357 阅读 · 0 评论 -
1100. Mars Numbers (20)
考查进制转换#include #include using namespace std;string t1[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};string t2[] = {"", "tam", "hel", "maa",原创 2016-03-04 11:32:44 · 396 阅读 · 0 评论 -
1013. Battle Over Cities (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. We must know immediately if we nee原创 2016-02-18 21:40:26 · 204 阅读 · 0 评论 -
1004. Counting Leaves (30)
A 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 with a line原创 2016-02-18 20:49:41 · 304 阅读 · 0 评论 -
1026. Table Tennis (30)
将排队的人按照到达的时间排序,然后开始轮询,会有四种情况:桌子是VIP,人是VIP,则直接分配桌子不是VIP,人也不是VIP,则直接分配桌子是VIP,人不是VIP,则往后找,是否存在一个VIP,且其到达时间早于该桌子的可用时间,找到则给VIP,当前的人继续等待,找不到这样的VIP,则把该桌子给当前用户桌子不是VIP,人是VIP,则检查桌子,是否还存在一张VIP桌子也空闲着,如果有这样一张V原创 2016-03-05 13:42:11 · 617 阅读 · 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 s原创 2016-02-19 13:47:13 · 217 阅读 · 0 评论 -
1015. Reversible Primes (20)
A 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 37 is also a pr原创 2016-02-19 14:17:05 · 212 阅读 · 0 评论 -
1016. Phone Bills (25)
1. 采用计算月初00:00:00到现在的分钟数,然后将算的钱差值得出,比直接时间差值再求钱数简单2. 题目中只强调至少有一条匹配成功的记录,不是说每个人都至少有一条匹配成功的记录,所以没有成功匹配记录的人不输出#include #include #include #include #include using namespace std;struct Record原创 2016-02-19 17:05:39 · 235 阅读 · 0 评论 -
1017. Queueing at Bank (25)
Suppose 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 behind the yellow li原创 2016-02-20 09:06:41 · 273 阅读 · 0 评论 -
1018. Public Bike Management (30)
DFS找符合条件的路径#include #include #include #include #include using namespace std;int cmax, n, sp, m, half;vector used;vector bikes;vector> edges;int minTime = numeric_limits::max();int m原创 2016-02-20 11:37:18 · 222 阅读 · 0 评论