
天梯赛 and PAT 解题报告
加油加油加油
晚风吻尽荷叶
道阻且长,行且将至。
展开
-
PAT 甲级 ☆1103 Integer Factorization (30分)【dfs + 剪枝】
1103Integer Factorization(30分)TheK−Pfactorization of a positive integerNis to writeNas the sum of theP-th power ofKpositive integers. You are supposed to write a program to find theK−Pfactorization ofNfor any positive integersN,KandP....原创 2020-11-22 18:16:45 · 482 阅读 · 0 评论 -
PAT-甲级 1022 Digital Library (30分)
1022Digital Library(30分)A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number as its ID. Given any query f...原创 2020-11-08 22:31:13 · 310 阅读 · 0 评论 -
PAT-甲级 ☆1021 Deepest Root (25分)【两次dfs】
1021Deepest Root(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 in a highest tree. Such a root is calledthe deepest root.I...原创 2020-11-08 21:45:18 · 316 阅读 · 0 评论 -
PAT-甲级 1019 General Palindromic Number (20分)【进制转换+判断回文】
1019General Palindromic Number(20分)A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.Although pali...原创 2020-11-08 18:05:14 · 270 阅读 · 0 评论 -
PAT-甲级 1017 Queueing at Bank (25分)【模拟】
1017Queueing at Bank(25分)Suppose a bank hasKwindows 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 line, until it is his/her tu...原创 2020-11-08 00:49:01 · 201 阅读 · 0 评论 -
PAT-甲级 1016 Phone Bills (25分)【模拟】
1016Phone Bills(25分)A long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a...原创 2020-11-07 22:07:43 · 515 阅读 · 1 评论 -
PAT-甲级 1015 Reversible Primes (20分)【素数打表】
1015Reversible Primes(20分)Areversible primein 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 prime.Now given any two p...原创 2020-11-07 01:08:13 · 185 阅读 · 0 评论 -
PAT-甲级 1014 Waiting in Line (30分)【模拟】
1014Waiting in Line(30分)Suppose a bank hasNwindows 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 space inside the yellow line in ...原创 2020-11-06 17:50:08 · 400 阅读 · 1 评论 -
PAT-甲级 1013 Battle Over Cities (25分)【图的连通性检测】
1013Battle 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 need to repair any other hi...原创 2020-11-06 11:01:03 · 260 阅读 · 0 评论 -
PAT-甲级 1012 The Best Rank (25分)【排序】
1012The 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 Algrbra), andE- English. At the mean time, we en...原创 2020-11-06 00:50:32 · 359 阅读 · 0 评论 -
PAT-甲级 1010 Radix (25分)【二分】
1010Radix(25分)Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer isyes, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive integersN1andN2, your task is to...原创 2020-11-05 21:42:25 · 349 阅读 · 0 评论 -
PAT-甲级 1007 Maximum Subsequence Sum (25分)【最长连续子序列和】
1007Maximum Subsequence Sum(25分)Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the la...原创 2020-10-31 13:33:43 · 199 阅读 · 0 评论 -
PAT-甲级 1004 Counting Leaves (30分)
1004Counting Leaves(30分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts with a line containing0&l...原创 2020-10-30 00:18:54 · 295 阅读 · 0 评论 -
L3-002 特殊堆栈 (30分) 【模拟 or 树状数组】
目录一、首先想到的是用vector模拟,但是超时了二、然后在网上学习了其他同学的做法:用stack模拟输入输出,用vector每次按顺序插入值,用lower_bound()函数三、后来又看到柳婼大神的树状数组求第k大的数解法L3-002特殊堆栈(30分)堆栈是一种经典的后进先出的线性结构,相关的操作主要有“入栈”(在堆栈顶插入一个元素)和“出栈”(将栈顶元素返回并从堆栈中删除)。本题要求你实现另一个附加的操作:“取中值”——即返回所有堆栈中元素键值的中值。给定 N 个元...原创 2020-09-12 19:34:25 · 563 阅读 · 1 评论 -
1090 危险品装箱 (25分)【map】
1090危险品装箱(25分)集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里。比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸。本题给定一张不相容物品的清单,需要你检查每一张集装箱货品清单,判断它们是否能装在同一只箱子里。输入格式:输入第一行给出两个正整数:N(≤104) 是成对的不相容物品的对数;M(≤100) 是集装箱货品清单的单数。随后数据分两大块给出。第一块有N行,每行给出一对不相容的物品。第二块有M行,每行给出一箱货物的清单,格式...原创 2020-09-09 12:50:11 · 259 阅读 · 0 评论 -
1091 N-自守数 (15分) 【字符串】
原题链接1091N-自守数(15分)如果某个数K的平方乘以N以后,结果的末尾几位数等于K,那么就称这个数为“N-自守数”。例如3×922=25392,而25392的末尾两位正好是92,所以92是一个3-自守数。本题就请你编写程序判断一个给定的数字是否关于某个N是N-自守数。输入格式:输入在第一行中给出正整数M(≤20),随后一行给出M个待检测的、不超过 1000 的正整数。输出格式:对每个需要检测的数字,如果它是N-自守数就在一...原创 2020-09-09 00:30:33 · 247 阅读 · 0 评论 -
1095 解码PAT准考证 (25分)
原题链接1095解码PAT准考证(25分)PAT 准考证号由 4 部分组成:第 1 位是级别,即T代表顶级;A代表甲级;B代表乙级; 第 2~4 位是考场编号,范围从 101 到 999; 第 5~10 位是考试日期,格式为年、月、日顺次各占 2 位; 最后 11~13 位是考生编号,范围从 000 到 999。现给定一系列考生的准考证号和他们的成绩,请你按照要求输出各种统计信息。输入格式:输入首先在一行中给出两个正整数N(≤104)和M(≤100),分别...原创 2020-09-09 00:19:06 · 200 阅读 · 0 评论 -
L2-010 排座位 (25分) 【并查集】
L2-010排座位(25分)布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位。无论如何,总不能把两个死对头排到同一张宴会桌旁!这个艰巨任务现在就交给你,对任何一对客人,请编写程序告诉主人他们是否能被安排同席。输入格式:输入第一行给出3个正整数:N(≤100),即前来参宴的宾客总人数,则这些人从1到N编号;M为已知两两宾客之间的关系数;K为查询的条数。随后M行,每行给出一对宾客之间的关系,格式为:宾客1 宾客2 关系,其中关系为1表示是朋友,-1表示是死对头。注意两个人不可能既是朋友又...原创 2020-08-30 16:40:40 · 179 阅读 · 0 评论 -
L2-013 红色警报 (25分)【搜索 或 并查集】
L2-013红色警报(25分)战争中保持各个城市间的连通性非常重要。本题要求你编写一个报警程序,当失去一个城市导致国家被分裂为多个无法连通的区域时,就发出红色警报。注意:若该国本来就不完全连通,是分裂的k个区域,而失去一个城市并不改变其他城市之间的连通性,则不要发出警报。输入格式:输入在第一行给出两个整数N(0<N≤500)和M(≤5000),分别为城市个数(于是默认城市从0到N-1编号)和连接两城市的通路条数。随后M行,每行给出一条通路所连接的两个城市的编号,其间以1个空...原创 2020-08-29 21:52:35 · 1579 阅读 · 0 评论 -
L2-023 图着色问题 (25分)【邻接点检测】
L2-023图着色问题(25分)代码长度限制 16 KB 时间限制 300 ms 内存限制 64 MB图着色问题是一个著名的NP完全问题。给定无向图G=(V,E),问可否用K种颜色为V中的每一个顶点分配一种颜色,使得不会有两个相邻顶点具有同一种颜色?但本题并不是要你解决这个着色问题,而是对给定的一种颜色分配,请你判断这是否是图着色问题的一个解。输入格式:输入在第一行给出3个整数V(0<V≤500)、E(≥0)和K(0<K≤V),分别是无向图的顶点数、...原创 2020-08-29 10:20:08 · 606 阅读 · 0 评论 -
L2-011 玩转二叉树 (25分) 【先序和中序构造二叉树、层序遍历】
L2-011玩转二叉树(25分)给定一棵二叉树的中序遍历和前序遍历,请你先将树做个镜面反转,再输出反转后的层序遍历的序列。所谓镜面反转,是指将所有非叶结点的左右孩子对换。这里假设键值都是互不相等的正整数。输入格式:输入第一行给出一个正整数N(≤30),是二叉树中结点的个数。第二行给出其中序遍历序列。第三行给出其前序遍历序列。数字间以空格分隔。输出格式:在一行中输出该树反转后的层序遍历的序列。数字间以1个空格分隔,行首尾不得有多余空格。输入样例:71 2 3 4 5 6 7..原创 2020-07-22 15:37:43 · 1909 阅读 · 1 评论 -
L2-021 点赞狂魔 (25分)【pair的应用】
L2-021点赞狂魔(25分)微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签,而你点赞的博文的类型,也间接刻画了你的特性。然而有这么一种人,他们会通过给自己看到的一切内容点赞来狂刷存在感,这种人就被称为“点赞狂魔”。他们点赞的标签非常分散,无法体现出明显的特性。本题就要求你写个程序,通过统计每个人点赞的不同标签的数量,找出前3名点赞狂魔。输入格式:输入在第一行给出一个正整数N(≤100),是待统计的用户数。随后N行,每行列出一位用户的点赞标签。格..原创 2020-07-21 23:20:37 · 172 阅读 · 0 评论 -
L1-064 估值一亿的AI核心代码 (20分)
L1-064估值一亿的AI核心代码(20分)本题要求你实现一个稍微更值钱一点的 AI 英文问答程序,规则是:无论用户说什么,首先把对方说的话在一行中原样打印出来; 消除原文中多余空格:把相邻单词间的多个空格换成 1 个空格,把行首尾的空格全部删掉,把标点符号前面的空格删掉; 把原文中所有大写英文字母变成小写,除了I; 把原文中所有独立的can you、could you对应地换成I can、I could—— 这里“独立”是指被空格或标点符号分隔开的单词; 把原文中所有独立的I...原创 2020-07-20 16:35:05 · 238 阅读 · 0 评论 -
L1-009 N个数求和 (20分)【附测试】
L1-009N个数求和(20分)本题的要求很简单,就是求N个数字的和。麻烦的是,这些数字是以有理数分子/分母的形式给出的,你输出的和也必须是有理数的形式。输入格式:输入第一行给出一个正整数N(≤100)。随后一行按格式a1/b1 a2/b2 ...给出N个有理数。题目保证所有分子和分母都在长整型范围内。另外,负数的符号一定出现在分子前面。输出格式:输出上述数字和的最简形式 —— 即将结果写成整数部分 分数部分,其中分数部分写成分子/分母,要求分子小于分母,且它们没有公因子。如果结果的..原创 2020-07-19 23:34:10 · 3996 阅读 · 9 评论