英文题面翻译
PAT (Advanced Level) Practice
题目链接
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 done to restore this property(性质). Figures 1-4 illustrate the rotation rules.
AVL树是自平衡树,在一棵AVL树中,任意两颗子树的高度相差不超过1,如果高度相差超过1,就重新平衡来恢复这个性质,图片1——4阐述了旋转规则
Now given a sequence of insertions, you are supposed to tell the root of the resulting AVL tree.现在给定一系列插入的节点,你要识别出得到的AVL树的根节点
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer N (<=20) which is the total number of keys to be inserted. Then N distinct integer keys are given in the next line. All the numbers in a line are separated by a space.
第一行一个正整数N表示插入的节点总数,接下来N个不同的节点值,在同一行以空格间隔分开
Output Specification:
For each test case, print ythe root of the resulting AVL tree in one line.
对于每个测试样例子,输出根节点
Sample Input 1:
5
88 70 61 96 120
Sample Output 1:
70
Sample Input 2:
7
88 70 61 96 120 90 65
Sample Output 2:
88
B. Dice Tower
题目链接
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
Bob在玩6面的骰子,骰子的网状图如下所示
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation(方向,朝向;定位) of each dice. Then he counts the number of visible pips on the faces of the dice.
他有无数个骰子,Bob想通过堆叠骰子来建一个塔,要确定每个骰子的朝向,然后它对骰子裸露在表面的数字进行计数。
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
示例如下,裸露在外面的数字是29,顶部是1,南面是5和3,西面是4 和2,北面是2和4,东面是3 和5
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.骰子的底面和两个骰子接触到的面看不见,所以不把这些面的数字加入总数
Bob also has t favourite integers xi, and for every such integer his goal is to build such a tower that the number of visible pips is exactly xi. For each of Bob’s favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.
BOb由t个最喜欢的数字xi,对每个数字它的目标是建一个骰子塔,使得裸露在外面的数字之和为x,对每一个他喜欢的数字,请判断是否能搭成这样一个塔
Input
The first line contains a single integer t (1≤t≤1000) — the number of favourite integers of Bob.Bob喜爱的数字个数
The second line contains t space-separated integers xi (1≤xi≤1018) — Bob’s favourite integers.
t个bob新欢的数字,由空格分隔开
Output
For each of Bob’s favourite integers,output “YES” if it is possible to build the tower, or “NO” otherwise (quotes for clarity).
Example
inputCopy
4
29 34 19 38
outputCopy
YES
YES
YES
NO
Note
The first example is mentioned in the problem statement.第一个样例在题目陈述里提及
In the second example, one can build the tower by flipping the top dice from the previous tower.可以翻转前一个样例中搭好的塔
In the third example, one can use a single die that has 5 on top.第3个样例用一个单独的骰子,使5在顶面
The fourth example is impossible.
题意:有n个筛子塔,给你一个数,问你把筛子堆起来,裸露在外的数字之和是否恰好为这个数。是输出YES 否输出NO
Problem A. Agrarian Reform
题目链接
The King of Squaredom is planning the agrarian reform(土地改革). The Squaredom has the form of rectangle of m × n squares. Squares are identified by pairs (x, y) where x ranges from 1 to m, and y ranges from 1to n. Each square is either occupied by a peasant’s house,or contains a swamp沼泽, or is a field. The King would like to assign peasants to fields, so that each peasant was assigned to exactly one field, and each field was assigned as most one peasant.
国王准备改革,这个国家土地的形状是m × n的方形,土地用数对(x, y)定义表示,每块土地要么被农民的房子占据,要么是沼泽或者田野。国王准备把农民分配到这些土地上,每个农民被指定一块领域,且每个领域最多为一个农民所有
The King asked his Minister of Agronomy to prepare the list of peasants. After that he would assign them to fields. The Private Counselor of the King has found out the algorithm the King will use to assign peasants to fields.把农民分配到土地上的算法
The King would look through the peasants in order they are listed by the Minister of Agronomy. For each peasant he would find the closest to his house field that has no peasant assigned to it yet. 每个农民找到距离他自己房子最近且没有分配给别人的土地。That field would be assigned to this peasant. If there are several such fields, the field which has the smallest x will be chosen, if there are still several such fields, the field which has the smallest y among them will be chosen. The distance between squares (x1, y1) and (x2, y2) is |x1 − x2| + |y1 − y2|.如果满足条件的土地很多,优先选取x值小的,若x值相等,优先选择y小的
The Minister of Agronomy would like to order peasants in such a way that the sum of distances between peasant and the field he is assigned to for all peasants were as small as possible. Help him to find such order.
农艺部通过以下规则分配农民:所有农民他到他被分配到的土地的距离之和最小
Input
The first line of the input file contains four integer numbers: m, n, k and s — the size of the field, the number of peasants, and the number of swamps, respectively (1 ≤ m, n ≤ 20, 1 ≤ k ≤ mn/2,0 ≤ s ≤ mn − 2k). The following k lines contain coordinates坐标 of squares where peasants live, the i-th of these lines contains two integer numbers xi, yi
(1 ≤ xi ≤ m, 1 ≤ yi ≤ n). No two peasants live in the same square.
The following s lines contain coordinates of squares containing swamps.
Output
Output k numbers — the order in which the Minister of Agronomy should order peasants so that the King assigned them to the fields in the optimal way.
m, n, k ,s分别表示土地尺寸大小,农民个数k,沼泽个数s
接下来k行包含农民住的地方的坐标,
输出k个数,表示给k个农广民分配土地的最佳顺序
Example
agrarian.in
3 5 5 0
2 3
2 4
1 3
2 2
3 3
agrarian.out
3 4 2 1 5
2392:Clear Cold Water
链接
The steamy, sweltering summers of Wisconsin’s dairy district stimulate the cows to slake their thirst. Farmer John pipes clear cold water into a set of N (3 <= N <= 99999; N odd) branching pipes conveniently numbered 1…N from a pump located at the barn. As the water flows through the pipes, the summer heat warms it. Bessie wants to find the coldest water so she can enjoy the weather more than any other cow.
She has mapped the entire set of branching pipes and noted that they form a tree with its root at the farm and furthermore that every branch point has exactly two pipes exiting from it. Surprisingly, every pipe is exactly one unit in length; of course, all N pipes connect up in one way or another to the pipe-tree.
Given the map of all the pipe connctions, make a list of the distance from the barn for every branching point and endpoint.Bessie will use the list to find the very coldest water.
The endpoint of a pipe, which might enter a branching point or might be a spigot, is named by the pipe’s number. The map contains C (1 <= C <= N) connections, each of which specifies three integers: the endpoint E_i (1 <= E_i <= N) of a pipe and two branching pipes B1_i and B2_i (2 <= B1_i <= N; 2 <= B2_i <= N). Pipe number 1 connects to the barn; the distance from its endpoint to the barn is 1.
输入
-
Line 1: Two space-separated integers: N and C
-
Lines 2…C+1: Line i+1 describes branching point i with three space-separated integers: E_i, B1_i, and B2_i
输出 -
Lines 1…N: Line i of the output contains a single integer that is the distance from the barn to the endpoint of pipe i
样例输入
5 2
3 5 4
1 2 3
样例输出
1
2
2
3
3
威斯康辛州乳制品区闷热潮湿的夏天刺激奶牛解渴。农民John将冷水导入一组N (3 <= N <= 99999;N奇)分支管方便编号1…从谷仓的水泵里出来。当水流过管道时,夏季的高温使它变暖。贝茜想找到最冷的水,这样她就能比其他奶牛更享受天气了。
她已经绘制了整个分支管道的集合,并注意到它们形成了一棵树根位于农场的树,而且每个分支点都恰好有两个从农场流出的管道。令人惊讶的是,每根管子都只有一个长度单位;当然,所有N个管道都以这样或那样的方式连接到管道树。
给定所有管道连接的映射,列出每一个分支点和端点到谷仓的距离。贝茜将利用这张单子找出最冷的水。
管道的端点(可能输入一个分支点,也可能是一个龙头)由管道的编号命名。映射包含C (1 <= C <= N)连接,每个连接指定三个整数:一个管道的端点E_i (1 <= E_i <= N)和两个分支管道B1_i和B2_i (2 <= B1_i <= N);2 <= B2_i <= N)管道1连接谷仓;从终点到谷仓的距离是1。
输入
*第1行:两个空格分隔的整数:N和C
*线2 . .C+1:第i+1行描述了具有三个空格分隔的整数:E_i、B1_i和B2_i的分支点i
输出
*线1 . .N:输出的第i行包含一个整数,即从谷仓到管道i端点的距离。
样例输入
5 2
3 5 4
1 2 3
样例输出
1
2
2
3
3
3340:RPN Calculator
题目链接
RPN类比(analogy)波兰表示法(Polish notation),一种在1920年被波兰数学家引进的前缀表示法(prefix notation),其中每个运算符(operator)都跟在它所有的操作数(operand)后面,RPN因后缀表示法而出名。
在RPN中操作符跟在操作数后面,比如,3加4写成 “3 4 +” 而不是 “3 + 4”.如果有若干(不止一个)操作,这个操作符在它的第二个操作数后立即进行运算操作。所以在传统中缀表示法(infix notation )里的 “3 − 4 + 5″在RPN里将表示为”3 4 − 5 +”,先做3减4,再加上5。RPN的一个优点就是它避免(obviate)了像在中缀表达式中对括号(parentheses)需求。尽管 “3 − 4 * 5” 可以写成 “3 − (4 * 5)”, 但写成 “(3 − 4) * 5″时意思就完全不同了, 只有括号(parentheses)才能消除模棱两可( disambiguate)的情况。在后缀表达式中,前者写成”3 4 5 * −” 和加上括号之后的”3 (4 5 ) −”一样不会有模棱两可的意思
你被要求设计一个RPN计算器。有“+”, “-“, “”, “/”(除数 divisor 不小于10^-9) 和“^”(指数运算符, 如果基数 b<=0, 指数(exponential) e 必须是一个不大于 10^9 的正整数) 。 你可以假设在运算中所有的数都符合fit into 双精度浮点数的精度要求。
此外,我们的计算器有记忆功能,每计算一个表达式,内存中的最小数字将被擦除,将替换计算得到的表达式的值。
输入
第一行包含一个整数n,它是我们计算器的内存大小。
从第二行开始,我们将给出n个数字,这是内存的初始值。除了last之外的每一行都有10个数字。
然后每行都有一个我们之前描述的有效RPN表达式,以“=”结尾,这是用于计算的命令。每个字词不超过20个字符。
输出
对于每个表达式,输出一行的值。
然后输出一个空行来分隔这两个部分。
最后,以递增的顺序输出内存中的所有数字,每行10个数字。
每个数字应格式化为科学记数法scientific notation,小数点decimal point后6位数和指数2位数,如C中的“%e”格式字符串printf()函数。一行中的数字应用空格分隔。
样例输入
4
1e6 1e-6 0.001 1000
1 2 + 3 4 + * =
1 0.1 / 8 ^ =
样例输出
2.100000e + 01
1.000000e + 08
2.100000e + 01 1.000000e + 03 1.000000e + 06 1.000000e + 08
提示
建议使用大量输入scanf()
%E格式输出在视窗环境下指数部分为3位,在系统的测试环境下为2位。
162:Post Office
传送门
有一条笔直的高速公路,沿着公路布满了村庄。公路用数轴表示,每个村庄的位置用整数坐标表示,没有两座村庄位置重合,两座村庄间的距离用两点距离的绝对值表示。
邮局将建在一些村庄,但并不需要要所有的村庄,一个村庄和在这个村庄的邮局坐标相同。为了建好邮局,要选好位置以便于每个村庄和它最近的邮局之间的距离之和最小。
你要写一个程序,根据给出的村庄坐标和邮局数量,计算每个村庄和它最近的邮局之间的距离之和 的最小值。
输入:
你的程序将标准输入,第一行包含两个整数:第一个是村庄数量V,1 <= V <= 300。第二个是邮局数量P, 1 <= P <= 30, P <= V. 第二行包含V个按升序排列的整数,分别代表村庄的位置,对于每个坐标,保证
1 <= X <= 10000.
输出:
第一行包含一个整数S,代表每个村庄和它最近的邮局之间的距离之和 的最小值。
样例输入:
10 5
1 2 3 6 7 9 11 22 44 50
样例输出
9
Not Escaping
题目链接
Ram正在被他傲慢自大的(arch)敌人Rahey追赶,他必须抵达建筑顶端并借助直升机逃离。然而建筑着火了,RAm必须选择最佳路径到达建筑顶端以丢失尽可能最小的生命值。
这个建筑有n层,每层有m个房间,用(i,j) 表示第i层第j个房间,此外,安装了k个梯子,第i个梯子可以使RAm从 (ai,bi) 到达(ci,di),但从其他方向不允许。RAm使用第i个梯子时可以获得hi个生命值。(对任意梯子确保ai<ci 。
如果Ram在第i层,它可以在这层上左右移动。然而转换楼层是有危险性的,从(i,j) 到 (i,k),它丢失
|j−k|⋅xi个生命值。Ram从(1,1)进入建筑物然而直升机在(n,m)。它选择最佳路径最少要损失多少生命值。注意结果可能是负数.如果无论选择哪条路都不能逃离Rahey的魔爪,则输出NO ESCAPE。
输入
第一行输入t——样例个数
每个样例
第一行3个整数 n,m,k,分别代表楼层数,房间数,梯子数
第二行包括n个整数x1,x2,…,xn
接下来k行描述梯子 梯子 i 通过 ai,bi,ci,di,hi表示,——连接的房间数量和可以从中获得的生命值
对每个梯子保证ai<ci ,且两个房间至多一个梯子,n,m,k的分别的总和不超过10^5
输出
Ram从(1,1)进入建筑物然而直升机在(n,m)。它选择最佳路径最少要损失多少生命值。注意结果可能是负数.如果无论选择哪条路都不能逃离Rahey的魔爪,则输出”NO ESCAPE”(都是大写字母,没有引号)。
Period
http://poj.org/problem?id=1961
Period
Description
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive),对于一个有着N个字符的字符串S,每个字符的ASCALL码在96和126之间) we want to know whether the prefix is a periodic string.我们想知道前缀是否是一个周期性的字段 That is, for each i (2 <= i <= N) 对于每个i (2 <= i <= N),我们想知道存在的最大的K值使得S的长度为i的前缀全为A,即A连续出现K次。we want to know the largest K > 1 (if there is one) such that the prefix of S with length i can be written as A^K ,that is A concatenated (连接的)K times, for some string A. Of course, we also want to know the period K.
Input
The input consists of several test cases. Each test case consists of two lines. The first one contains N (2 <= N <= 1 000 000) – the size of the string S.The second line contains the string S. The input file ends with a line, having the
number zero on it.输入文件以最后一行为0为结束标志。
Output
For each test case, output “Test case #” and the consecutive(连续的不间断的) test case number on a single line; then, for each prefix with length i that has a period K > 1, output the prefix size i and the period K separated by a single space; the prefix sizes must be in increasing order. Print a blank line after each test case.
以前缀的长度为比较条件升序输出
Sample Input
3
aaa
12
aabaabaabaab
0
Sample Output
Test case #1
2 2
3 3
Test case #2
2 2
6 2
9 3
12 4
给出一个字符串,判断该字符串的前缀中是否存在连续的子串(即同一子串至少连续出现两次)
字符串S前i个字符中即求最小循环节出现的次数
E. Math Test
E. Math Test
Petya is a math teacher. n of his students has written a test consisting of m questions. For each student, it is known which questions he has answered correctly and which he has not.每个学生都知道自己答对答错
If the student answers the j-th question correctly, he gets pj points (otherwise, he gets 0 points).如果一个学生正确回答了第j个问题,就能得到pj分,否则得0分) Moreover, the points for the questions are distributed in such a way that the array p is a permutation of numbers from 1 to m.(这道题目的分数分布方式是:从1到m这些数的排列组合,放在数组p中
For the i-th student, Petya knows that he expects to get xi points for the test. Petya wonders how unexpected the results could be. Petya believes that the surprise value of the results for students is equal to ∑i=1n|xi−ri|, where ri is the number of points that the i-th student has got for the test.
对于第i位学生,Petya知道他期望得多少分,Petya想知道结果有多出人意料,意外值等于∑i=1n|xi−ri|,ri是第i位学生这次测试所得到的分数
Your task is to help Petya find such a permutation p for which the surprise value of the results is maximum possible. If there are multiple answers, print any of them.(你的任务是帮Petya找到p数组的一个组合使得surprise value达到最大。
Input
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains two integers n and m (1≤n≤10; 1≤m≤104) — the number of students and the number of questions, respectively.分别表示学生数和问题数
The second line contains n integers x1,x2,…,xn (0≤xi≤m(m+1)2), where xi is the number of points that the i-th student expects to get.分别表示第i个学生渴望得到的分数
This is followed by n lines, the i-th line contains the string si (|si|=m;si,j∈{0,1}), where si,j is 1 if the i-th student has answered the j-th question correctly, and 0 otherwise.接下来n行,第i行包含一个字符串si,字符串的第j个字符是1或0,1表示这第i位学生答对了第j道题。
The sum of m for all test cases does not exceed 104.
Output
For each test case, print m integers — a permutation p for which the surprise value of the results is maximum possible. If there are multiple answers, print any of them.
Example
input
3
4 3
5 1 2 2
110
100
101
100
4 4
6 2 0 10
1001
0010
0110
0101
3 6
20 3 15
010110
000101
111111
output
3 1 2
2 3 4 1
3 1 4 5 2 6
CF540D Bad Luck Island
题目链接
题目描述
岛上住了三个物种,分别有r,s,p个: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably相等概率的)三个物种随机遇见,每两个物种等概率相遇, 如果两个不同物种遇上,厮杀规则如下(石头剪刀布的规则): a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.你的任务是决定每个物种在经历足够长的一段时间后,唯一存活下来的概率
输入格式
The single line contains three integers rr , ss and pp ( 1<=r,s,p<=1001<=r,s,p<=100 ) — the original number of individuals in the species of rock, scissors and paper, respectively.一行三个整数,分别代表三个物种各自的原始数量
输出格式
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn’t exceed 10{-9}输出三个空格分隔开的实数,求出最后唯一存在的单一种族的概率。如果结果的相对误差或者绝对误差不超过10{-9},结果将视为正确。
题意翻译
给三种人,分别是r,s,p个;
在孤岛上,每两个不同种人相遇则互吃,r吃s,s吃p,p吃r
求最后留下单一种族的概率
输入输出样例
输入 #1
2 2 2
输出 #1
0.333333333333 0.333333333333 0.333333333333
输入 #2
2 1 2
输出 #2
0.150000000000 0.300000000000 0.550000000000
输入 #3
1 1 3
输出 #3
0.057142857143 0.657142857143 0.285714285714
1115 Counting Nodes in a BST (30 分)
题目链接
1115 Counting Nodes in a BST (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 or equal to the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
Both the left and right subtrees must also be binary search trees.
一个节点的左子树的所有节点的值都小于等于该节点的值,它右子树的所有节点的值都大于等于该节点的值左子树和右子树都必须是二叉树
Insert a sequence of numbers into an initially empty binary search tree. Then you are supposed to count the total number of nodes in the lowest 2 levels of the resulting tree.
插入一串数字到初始为空的二叉树中,你要计算最低两层树的所有节点之和
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤1000) which is the size of the input sequence. Then given in the next line are the N integers in [−1000,1000] which are supposed to be inserted into an initially empty binary search tree.
第一行输入这串数据的个数,接下来给出n个[−1000,1000]范围内的整数,插入到初始为空的二叉树中
Output Specification:
For each case, print in one line the numbers of nodes in the lowest 2 levels of the resulting tree in the format:
n1 + n2 = n
where n1 is the number of nodes in the lowest level, n2 is that of the level above, and n is the sum.
Sample Input:
9
25 30 42 16 20 20 35 -5 28
Sample Output:
2 + 4 = 6
C. Beautiful Numbers
题目链接
Vitaly 是一个非常奇怪的人。他有两个偏爱的数字 a 和 b 。如果一个正整数的十进制表示,仅包含数字 a 和 b,则 Vitaly 将这个正整数称之为 good 。如果某个 good 数 A 的各位数字之和也是一个 good 数,那么 Vitaly 就把这个 good 数 A 称之为 excellent 。
例如,假定 Vitaly 的偏爱数字是 1 和 3,那么数 12 不是 good,而数 13 或 311 却是。另外,数 111 是 excellent,数 11 却不是。
现在,Vitaly 想要知道,有多少个长度恰好是 n 的 excellent 数。由于这个数目可能很大,他请您在计数时,对 1000000007 (109 + 7) 取模即可。
一个数的长度是指,它的十进制表示,有多少位数字 (不含前导的零)。
输入
第一行包含了三个整数: a, b, n (1 ≤ a < b ≤ 9, 1 ≤ n ≤ 106)。
输出
打印单个整数 — 问题的答案对 1000000007 (109 + 7) 取模。
示例
输入
1 3 3
输出
1
输入
2 3 10
输出
165
今天的文章英文题面翻译分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/62285.html