个人学习记录,代码难免不尽人意。
这次考试,e,第一题我看好多人都没理解题意做错了,还有第四题真的是比较意外,之前做的题都是给序列建树,但是这次让判断是否可以生成树,之前从来没有遇到过这类题,所以第四题要好好记住。第二题和第三题到是很简单。
A-1 Reduction of Proper Fractions
A Proper Fraction(真分数)is a fraction where the numerator(分子)is less than the denominator(分母). To reduce a fraction, we are supposed to cross out any common factors between the numerator and the denominator.
Here is another way to do the reduction: simply cross out any common digits. In most of the cases, this way cannot give the correct result. However, sometimes it happends to work! For example: 26/65 = 2/5 where 6 is crossed out.
Now given a proper fraction, you are supposed to tell if this simple reduction works or not.
Input Specification: Output Specification: Sample Input 1: 题目的意思是“对于A和B中的每一个相同的字符都去除,而不是说存在相同的都要去除”。(我感觉出题人就喜欢不把话说明白让你猜哈哈),举个例子 a=1112,b=1234,正确答案c=112,d=34 A-2 Luggage Pickup Now assume that we have a special airport that has only one pickup window for each conveyor belt. The passengers are asked to line up to pick up their luggage one by one at the window. But if one arrives at the window yet finds out that one is not the owner of that luggage, one will have to move to the end of the queue and wait for the next turn. At the mean time, the luggage at the window will wait until its owner picks it up. Suppose that each turn takes 1 minute, your job is to calculate the total time taken to clear the conveyor belt, and the average waiting time for the passengers. For example, assume that luggage i belongs to passenger i. If the luggage come in order 1, 2, 3, and the passengers come in order 2, 1, 3. Luggage 1 will wait for 2 minutes to be picked up by passenger 1. Then the luggage queue contains 2 and 3, and the passenger queue contains 3 and 2. So luggage 2 will wait for 2 minutes to be picked up by passenger 2. And finally 3 is done at the 5th minute. The average waiting time for the passengers is (2+4+5)/3≈3.7. Input Specification: All the numbers in a line are separated by a space. Output Specification: Sample Input: 这道题就是很简单的模拟题,不多说了 It is a bit complicated to find the articulation points. Here you are only asked to check if a given vertex is an articulation point or not. Input Specification: v1 v2 Finally a line of queries are given, which contains K vertices to be checked. The numbers in a line are separated by spaces. Output Specification: Sample Input: 这道题也很简单,不多说了。 A-4 Check Inorder Traversals Now given a pair of postorder and preorder traversal sequences, you are supposed to check a set of inorder traversal sequences, and answer whether or not they are indeed inorder traversal sequences of the tree. Input Specification: Then another positive integer K (≤ 10) is given, followed by K lines of inorder traversal sequences. Each sequence consists of N positive integers. All the numbers in a line are separated by a space. Output Specification: On the other hand, there is another possible case that the given pre- and postorder traversal sequences can NOT form any tree at all. In that case, first print in a line Are you kidding me?. Then for each inorder traversal sequence of the input, try to construct a tree with the given preorder traversal sequence, and output in a line the correct postorder traversal sequence. If it is still impossible, output You must be kidding me! instead. Sample Input 1: 这道题需要熟练掌握!一开始我想的有点复杂了,其实判断前序序列和后序序列能不能生成一个二叉树只需要判断pre的第一个和post的最后一个是否相等即可!除此之外,题目还有一个坑点是两个序列不一定是完全覆盖的,需要判断! 各位肯定对用前序序列和中序序列建树的过程和方法烂熟于心了!那么我们就可以用模板来举一反三求解此题。我们可以用同样的方法来处理左右子树,如果各自序列对应的根节点不相等就返回false,除此之外,因题目的特殊要求,如果在第二个序列查找不到对应的数字,就要返回false。
Each input file contains one test case, with the numerator a and the denominator b of the proper fraction given in a line, separated by a space. It is guaranteed that 0
For each test case, print in a line both fractions before and after the simple reduction. If they are equal, put a = between them; else put != instead. The format is either a/b = c/d or a/b != c/d.
39 195
Sample Output 1:
39/195 = 3/15
Sample Input 2:
1234 2345
Sample Output 2:
1234/2345 != 1/5
Sample Input 3:
1234 5678
Sample Output 3:
1234/5678 = 1234/5678#include
明白了这个,这道题就是送分题了。
When a flight arrives, the passengers will go to the Arrivals area to pick up their baggage from a luggage conveyor belt (行李传送带).
Each input file contains one test case. The first line gives a positive integer N (≤10 3 ). Then N numbers are given in the next line, which is a permutation of the integers in [1,N], representing the passenger queue. Here we are assuming that the luggage queue is in order of 1, 2, …, N, and the i-th luggage belongs to passenger i.
For each test case, print in a line the total time taken to clear the conveyor belt, and the average waiting time for the passengers (output 1 decimal place). The numbers must be separated by 1 space, and there must be no extra space at the beginning or the end of the line.
5
3 5 1 2 4
Sample Output:
9 6.0#include
In graph theory, given a connected graph G, the vertices whose removal would disconnect G are known as articulation points. For example, vertices 1, 3, 5, and 7 are the articulation points in the graph shown by the above figure (also given by the sample input).
Each input file contains one test case. For each case, the first line contains 3 positive integers: N (≤10
3
), M (≤10
4
), and K (≤100), which are the number of vertices, the number of edges, and the number of queries, respectively. Then M lines follow, each gives an undirected edge in the format:
where v1 and v2 are the two ends of an edge. Here we assume that all the vertices are numbered from 0 to N−1. It is guaranteed that v1 is never the same as v2, and the graph is connected.
Output a string of 0’s and 1’s in a line. That is, for each query, print 1 if the given vertex is an articulation point, or 0 if not. There must be no space between the answers.
10 11 8
0 1
8 7
9 7
1 2
1 3
3 5
5 7
2 4
3 4
5 6
6 7
5 2 9 1 6 3 2 7
Sample Output:
10010101#include
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences, or preorder and inorder traversal sequences. However, if only the postorder and preorder traversal sequences are given, the corresponding tree may no longer be unique.
Each input file contains one test case. For each case, the first line gives a positive integer N (≤ 30), the total number of nodes in the binary tree. The second line gives the preorder sequence and the third line gives the postorder sequence.
For each inorder traversal sequence, print in a line Yes if it is an inorder traversal sequence of the tree, or No if not.
4
1 2 3 4
2 4 3 1
4
2 1 3 4
1 2 3 4
2 1 4 3
2 1 5 6
Sample Output 1:
Yes
No
Yes
No
Sample Input 2:
7
1 2 3 4 6 7 5
6 7 5 4 3 2 1
3
2 1 6 4 7 3 5
2 1 6 7 4 3 5
2 3 1 7 4 5 6
Sample Output 2:
Are you kidding me?
2 6 7 4 5 3 1
2 7 6 4 5 3 1
You must be kidding me!#include