Pat&&Pta
文章平均质量分 75
Pat&&Pta
-Hello_狂奔的蜗牛
Fly!!!
展开
-
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原创 2017-02-16 17:41:22 · 156 阅读 · 0 评论 -
1006. Sign In and Sign Out (25)
https://www.patest.cn/contests/pat-a-practise/1006#include <cstdio>#include <iostream>#include <string>#include <cstdlib>using namespace std;struct persons { string name; string Sign_in_ti原创 2017-02-18 09:59:45 · 214 阅读 · 0 评论 -
1005. Spell It Right (20)
https://www.patest.cn/contests/pat-a-practise/1005#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <cstdlib>using namespace std;string SpellRight(int i) { switc原创 2017-02-18 10:01:27 · 189 阅读 · 0 评论 -
1001. A+B Format (20)
https://www.patest.cn/contests/pat-a-practise/1001#include <cstdio>#include <iostream>#include <cmath>using namespace std;int main(){ int a, b,str[100],k = 0; cin >> a >> b; int sum = a + b;原创 2017-02-18 10:03:09 · 180 阅读 · 0 评论 -
1007. Maximum Subsequence Sum (25)
#include <cstdio>#include <iostream>using namespace std;int a[10001];int main(){ int k; scanf("%d", &k); for (int i = 0; i < k; i++){ scanf("%d", &a[i]); } int sum = 0, start = 0, end原创 2017-02-18 12:17:15 · 149 阅读 · 0 评论 -
1008. Elevator (20)
http://www.patest.cn/contests/pat-a-practise/1008#include #include using namespace std;int main () { int n; int val[101]; cin >> n; for (int i = 0; i < n; i++) { scanf("%d",原创 2017-02-18 14:47:21 · 169 阅读 · 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 ye原创 2017-02-21 09:34:14 · 265 阅读 · 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原创 2017-02-16 13:01:05 · 265 阅读 · 0 评论 -
1019. General Palindromic Number (20)
https://www.patest.cn/contests/pat-a-practise/1019#include #include #include using namespace std;int stnum[1000] = {0};int Transfer(int num,int b) { int cnt = 0; while (num) { i原创 2017-02-21 21:18:54 · 223 阅读 · 0 评论 -
1022. Digital Library (30)
https//注意scanf("%s"),字符串读取不能有空格//注意一个字符串是以"\0"结束的,他的int值是0#include #include #include #include using namespace std;struct Book{ int ID; char title[200]; char author[200]; char w原创 2017-02-22 16:46:32 · 220 阅读 · 0 评论 -
1024. Palindromic Number (25)
这个很常规,我用到了string的字符串反转函数reverse(),需要加头文件#include ,还有就是大数的加法。其次我第一次提交就20分,后来发现是如果input的那个数本身就是回文的话,那么直接output 这个数和0,这个就满分了。A number that will be the same when it is written forwards or backwards is k原创 2017-02-23 11:02:27 · 171 阅读 · 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原创 2017-02-23 16:59:40 · 185 阅读 · 0 评论 -
1002. A+B for Polynomials (25)
#include #include #include using namespace std;int main() { float A[1001] = {0}; float B[1001] = {0}; int k; cin >> k; float c; int e; for (int i = 0; i < k; i++) {原创 2017-02-16 09:49:07 · 277 阅读 · 0 评论 -
1100. Mars Numbers (20)
People on Mars count their numbers with base 13:Zero on Earth is called "tret" on Mars.The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars原创 2017-03-04 07:36:45 · 182 阅读 · 0 评论 -
1121. Damn Single (25)
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.Input Specification: Each inp原创 2017-02-24 22:47:06 · 234 阅读 · 0 评论 -
1043. Is It a Binary Search Tree (25)
https://www.patest.cn/contests/pat-a-practise/1043//给定一克BST,构建BST,判断给定的序列是否是构建好的这棵BST的前序序列/* 如果是的话 :输出这棵树的后序 。。 或者判断这棵树进行左右子树翻转后,如果这棵BST的前序序列是给定的序列, 输出翻转后的这棵树的后序。*/#include #include using n原创 2017-03-04 10:15:52 · 216 阅读 · 0 评论 -
1127. ZigZagging on a Tree (30)
https://www.patest.cn/contests/pat-a-practise/1127我想到一种直接暴力的方法,就是中序后序建树以后,直接用一个双向队列进行层序遍历,//第一种思路//我的思路就是用了一个deque//从第二层开始,当遍历偶数层数时,左边队头出去,右边进来,//奇数层数时,deque右边出去,左边进来。#include #include #incl原创 2017-03-05 10:35:02 · 1530 阅读 · 0 评论 -
1126. Eulerian Path (25)
https://www.patest.cn/contests/pat-a-practise/1126/*离散数学中对于欧拉图的定义:通过图(有向或无向)中所有边一次且仅一次行遍所有顶点的通路 称作欧拉通路,通过图中所有边一次且仅一次行遍所有顶点的回路称作欧拉回路,具有欧拉回路的图为欧拉图,具有欧拉通路的图为半欧拉图。*//* 定理1:无向图G是欧拉图当且仅当G时连通图且没有奇度原创 2017-03-06 09:05:25 · 266 阅读 · 0 评论 -
1009. Product of Polynomials (25)
https://www.patest.cn/contests/pat-a-practise/1009#include #include #include using namespace std;const int N = 1001;double a[N],b[N],c[2*N];int main() { int n; scanf("%d",&n); int index; d原创 2017-02-18 16:20:37 · 402 阅读 · 0 评论 -
1028. List Sorting (25) java
https://www.patest.cn/contests/pat-a-practise/1028#include <iostream>#include <cstdio>#include <queue>#include <algorithm>#include <cstring>#include <vector>using namespace std;typedef struct no原创 2017-05-01 16:40:19 · 343 阅读 · 0 评论 -
1021. Deepest 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 i原创 2017-07-08 06:35:19 · 209 阅读 · 0 评论 -
1016. Phone Bills (25)
大模拟+排序 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a原创 2017-07-30 21:32:51 · 231 阅读 · 0 评论 -
1123. Is It a Complete AVL Tree (30)
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原创 2017-08-09 15:18:11 · 134 阅读 · 0 评论 -
习题3.4 最长连续递增子序列
给定一个顺序存储的线性表,请设计一个算法查找该线性表中最长的连续递增子序列。例如,(1,9,2,5,7,3,4,6,8,0)中最长的递增子序列为(3,4,6,8)。 输入格式: 输入第1行给出正整数 nn n( ≤105\le 10^5 ≤10 5 );第2行给出 nn n个整数,其间以空格分隔。 输出格式: 在一行中输出第一次出现的最长连续递增子序列,数字之间用空格原创 2017-08-02 13:58:41 · 540 阅读 · 0 评论 -
1021. 个位数统计 (15)
给定一个k位整数N = dk-1*10k-1 + … + d1*101 + d0 (0<=di<=9, i=0,…,k-1, dk-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,则有2个0,3个1,和1个3。输入格式:每个输入包含1个测试用例,即一个不超过1000位的正整数N。输出格式:对N中每一种不同的个位数字,以D:M的格式在一行中输出该位数字D及其在N中原创 2017-08-16 17:40:22 · 183 阅读 · 0 评论 -
1028. 人口普查(20)
某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过200岁的老人,而今天是2014年9月6日,所以超过200岁的生日和未出生的生日都是不合理的,应该被过滤掉。输入格式:输入在第一行给出正整数N,取值在(0, 105];随后N行,每行给出1个人的姓名(由不超过5个英文字母组成的字符串)、以及按原创 2017-08-16 23:28:41 · 134 阅读 · 0 评论 -
1015. 德才论 (25)
宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。输入格式:输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录原创 2017-08-17 10:01:06 · 120 阅读 · 0 评论 -
1020. 月饼 (25)
月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有3种月饼,其库存量分别为18、15、10万吨,总售价分别为75、72、45亿元。如果市场的最大需求量只有20万吨,那么我们最大收益策略应该是卖出全部15万吨第2种月饼、以及原创 2017-08-17 12:00:15 · 206 阅读 · 0 评论 -
1068. 万绿丛中一点红(20)
对于计算机而言,颜色不过是像素点对应的一个24位的数值。现给定一幅分辨率为MxN的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围8个相邻像素的颜色差充分大。输入格式:输入第一行给出三个正整数,分别是M和N(<= 1000),即图像的分辨率;以及TOL,是所求像素点与相邻点的颜色差阈值,色差超过TOL的点才被考虑。随后N行,每行给出M个像素的颜色值,范围在[0,原创 2017-08-10 12:52:37 · 153 阅读 · 0 评论 -
1023. 组个最小数 (20)
给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们得到的最小的数就是10015558。现给定数字,请编写程序输出能够组成的最小的数。输入格式:每个输入包含1个测试用例。每个测试用例在一行中给出10个非负整数,顺序表示我们拥有数字0、数字1、……数字9的个数。整数间用一个空格分隔。10原创 2017-08-18 09:58:58 · 119 阅读 · 0 评论 -
1024. 科学计数法 (20)
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]”.”[0-9]+E[+-][0-9]+,即数字的整数部分只有1位,小数部分至少有1位,该数字及其指数部分的正负号即使对正数也必定明确给出。现以科学计数法的格式给出实数A,请编写程序按普通数字表示法输出A,并保证所有有效位都被保留。输入格式:每个输入包含1个测试用例,即一个以科学计数法表示的实数A。该数字的原创 2017-08-18 09:59:31 · 216 阅读 · 0 评论 -
1026. 程序运行时间(15)
要获得一个C语言程序的运行时间,常用的方法是调用头文件time.h,其中提供了clock()函数,可以捕捉从程序开始运行到clock()被调用时所耗费的时间。这个时间单位是clock tick,即“时钟打点”。同时还有一个常数CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数f的运行时间,我们只要在调用f之前先调用clock(),获得一个时钟打点数C1;在f执行完成后再调用cl原创 2017-08-18 10:39:48 · 121 阅读 · 0 评论 -
1029. 旧键盘(20)
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。输入格式:输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。输出格式:按照发现顺序,在一行中输出坏掉的键。其中英文字母原创 2017-08-18 10:57:55 · 168 阅读 · 0 评论 -
1109. Group Photo (25)
Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:The number of people in each row must be N/K (round down to the nearest integer),原创 2017-08-11 11:31:43 · 200 阅读 · 0 评论 -
1030. 完美数列(25)
给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M <= m * p,则称这个数列是完美数列。现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。输入格式:输入第一行给出两个正整数N和p,其中N(<= 105)是输入的正整数的个数,p(<= 109)是给定的参数。第二行给出N个正整数,每个数不超过109。输出格式:在一行中输出最多可以选择多少个数可以用它们原创 2017-08-18 19:15:28 · 150 阅读 · 0 评论 -
1031. 查验身份证(15)
一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:Z:0 1 2 3 4 5 6 7 8 9 10 M:1 0 X 9 8 7 6 5 4 3 2现在给定一些身份证号码原创 2017-08-18 19:38:51 · 126 阅读 · 0 评论 -
1032. 挖掘机技术哪家强(20)
为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。输入格式:输入在第1行给出不超过105的正整数N,即参赛人数。随后N行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从1开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。输出格式:在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。原创 2017-08-18 19:50:28 · 141 阅读 · 0 评论 -
1033. 旧键盘打字(20)
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?输入格式:输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过105个字符的串。可用的字符包括字母[a-z, A-Z]、数字0-9、以及下划线“_”(代表空格)、“,”、“.”、“-”、“+”(代表上档键)。题目保原创 2017-08-18 22:23:27 · 106 阅读 · 0 评论 -
1037. 在霍格沃茨找零钱(20)
如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱P和他实付的钱A,你的任务是写一个程序来计算他应该被找的零钱。输入格式:输入在1行中分别给出P和A,格式为“Galleon.Sickle.Knut”,其间用1个空格分隔。这里Galleon原创 2017-08-19 07:40:27 · 157 阅读 · 0 评论 -
1104. Sum of Number Segments (20)
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence {0.1, 0.2, 0.3, 0.4}, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (原创 2017-08-19 15:11:21 · 135 阅读 · 0 评论