BestCoder Round #54(Div.2) (4/4) (Div.1) (3/4)

maksyuki 发表于 比赛 分类,标签:
0

A problem of sorting

Problem Description

There are many people's name and birth in a list.Your task is to print the name from young to old.(There is no pair of two has the same age.)

Input

First line contains a single integer T≤100 which denotes the number of test cases.

For each test case, there is an positive integer n(1≤n≤100) which denotes the number of people,and next n lines,each line has a name and a birth's year(1900-2015) separated by one space.

The length of name is positive and not larger than 100.Notice name only contain letter(s),digit(s) and space(s).

Output

For each case, output n lines.

Sample Input

2

1

FancyCoder 1996

2

FancyCoder 1996

xyz111 1997

Sample Output

FancyCoder

xyz111

FancyCoder

Source

BestCoder Round #54 (div.2)

 

题目类型:简单字符串处理

算法分析:一次将一整行都读入进来,然后从后向前将年份和名字分离开来,最后直接排序输出答案即可

 

B The Factor

Problem Description

There is a sequence of n positive integers. Fancycoder is addicted to learn their product, but this product may be extremely huge! However, it is lucky that FancyCoder only needs to find out one factor of this huge product: the smallest factor that contains more than 2 factors(including itself; i.e. 4 has 3 factors so that it is a qualified factor). You need to find it out and print it. As we know, there may be none of such factors; in this occasion, please print -1 instead.

Input

The first line contains one integer T (1≤T≤15), which represents the number of testcases.

For each testcase, there are two lines:

1. The first line contains one integer denoting the value of n (1≤n≤100).

2. The second line contains n integers a1,…,an (1≤a1,…,an≤2×109), which denote these n positive integers.

Output

Print T answers in T lines.

Sample Input

2

3

1 2 3

5

6 6 6 6 6

Sample Output

6

4

Source

BestCoder Round #54 (div.2)

 

题目类型:素因子分解

算法分析:直接将输入的数进行素因子分解,最后进行一次排序。如果len的长度大于等于2,则有解,且解就是最小的两个数的乘积。否则无解。注意合数有小于等于其根号值的素因子,但是输入的数可能是一个素数!!!所以直接使用factor[i]表示素数i的个数是会RE的~~

 

C Geometric Progression

Problem Description

Determine whether a sequence is a Geometric progression or not.

In mathematics, a **geometric progression**, also known as a **geometric sequence**, is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, ... is a geometric progression with common ratio 3. Similarly 10, 5, 2.5, 1.25, ... is a geometric sequence with common ratio 1/2.

Examples of a geometric sequence are powers rk of a fixed number r, such as 2k and 3k. The general form of a geometric sequence is

a, ar, ar2, ar3, ar4, …

where r ≠ 0 is the common ratio and a is a scale factor, equal to the sequence's start value.

Input

First line contains a single integer T(T≤20) which denotes the number of test cases.

For each test case, there is an positive integer n(1≤n≤100) which denotes the length of sequence,and next line has n nonnegative numbers Ai which allow leading zero.The digit's length of Ai no larger than 100.

Output

For each case, output "Yes" or "No".

Sample Input

4

1

0

3

1  1  1

3

1 4 2

5

16 8 4 2 1

Sample Output

Yes

Yes

No

Yes

Source

BestCoder Round #54 (div.2)

 

题目类型:高精度计算

算法分析:首先全零数列是可以的,然后对于非全零数列,使用a[i] * a[i]是否等于a[i-1] * a[i+1]来判断,注意这里要额外判断a[i]是否等于0!!!

 

D Reflect

Problem Description

We send a light from one point on a mirror material circle,it reflects N times and return the original point firstly.Your task is calcuate the number of schemes.

Input

First line contains a single integer T(T≤10) which denotes the number of test cases.

For each test case, there is an positive integer N(N≤106).

Output

For each case, output the answer.

Sample Input

14

Sample Output

4

Source

BestCoder Round #54 (div.2)

 

题目类型:欧拉函数求解

算法分析:如果选择一个发射器与水平方向的角度a,则圆心角转过的角度是2a。为了使得经过n次反射之后光线还能回来,需要满足2a * (n + 1) = 2 * k * PI。化简得a = k / (n + 1) * PI,此时只要找到合适的k,使得a是一个最简分数即可,这个问题转换成了求解1~n+1中与n+1互素的数的个数,直接打出euler函数表,查询即可