# 山东大学（威海）程序设计竞赛2020新星赛（线上模拟赛）题解

## factorial（数论，简单模拟）

In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.

### 输入格式

Input consists of several lines of integer numbers. The first line contains an integer T, which is the number of cases to be tested, followed by T lines, one integer 1 ≤ n ≤ 10000000 on each line.

1≤T≤10

### 输出格式

The output contains the number of digits in the factorial of the integers appearing in the input.

## exam（排序算法，模拟）

The final exam is over. In order to give rewards, the teacher should rank the students in the class.

There are N students in the class. This semester, they have learned K courses.

The student number of the i-th student is Xi, and his score of the j-th course is expressed as Aij.

The ranking rules are as follows:

If the scores of two students are different, the first course with different scores will be the basis for ranking, and the one with higher scores will come first.

If the scores of the two students are identical, the one with the smaller student number will come first.

### 输入格式

The first line contains N, K (N≤1000,K≤10).

In the following N lines, the i-th line contains K+1 integers X**i Ai*1 *Ai2 Ai3 … Ai**k. (X**i<100000,Aij<100000)

Guarantee student number is different.

### 输出格式

A line contains n integers, which are the student numbers from the first to the last, separated by spaces.

There should be a space after the last number

## stack（超级水题，模拟）

Xiaoming is learning stack. Stack is a last in, first out data structure. There are only two operations: adding an element to the end of the stack and taking out the end element. Now Xiaoming asks you to help him simulate the operation of the stack.

### 输入格式

The first line contains an integer n indicating how many operations there are. (N≤100000)

Next N lines, two integers A and B per line. A = 1 means to add B to the tail of the stack, A = 2 means to take out the tail element of B times. (B<100000)

The stack is initially empty. Ensure that elements are not removed from the empty stack.

### 输出格式

The first line, an integer m, indicates how many elements are left in the stack.

The second line, m integers, lists the m elements from the beginning to the end of the stack, separated by spaces.

## Hateful Fat（数论，计算几何）

LCY lost his pen when he was studying, which is really a bad situation, because his eyes have been blocked by his fat. So can you tell him the positional relationship between him and the pencil?

For given three points p0,p1,p2,

print “ COUNTER_CLOCKWISE” if p0,p1,p2 make a counterclockwise turn (1)

print “ CLOCKWISE” if p0,p1,p2 make a clockwise turn (2),

print “ ONLINE_BACK” if p2 is on a line p2,p0,p1 in this order (3),

print “ ONLINE_FRONT “if p2 is on a line p0,p1,p2 in this order (4),

print “ ON_SEGMENT” if p2 is on a segment p0p1(5).

### Input:

In the first line, integer coordinates of p0 and p1 are given.

The next line gives an integer q, which represents the number of queries.

Then, q queries are given for integer coordinates of p2.

### Output:

For each query, print the above mentioned status.

## prime（数论，素数筛）

Xiaoming is learning prime number, which is a integer greater than 1 and can only be divided by 1 and itself. Xiao Ming has learned how to judge whether a number is prime. Now, he wants to know how many prime numbers are in [1, N].

### 输入格式

An integer N.(N<=10000000)

### 输出格式

An integer represents how many prime numbers are in [1, N].

## lcy‘s weight（高精度）

During the holiday, LCY has been eating snacks, but sometimes he also exercises, so his weight has been changing. At the same time, LCY is an excellent college student, so he records the change of his weight the day before every day. But n days later, he found that he could not know how heavy he was now, but he could remember his weight on the first day as M. So LCY found smart you. I hope you can help him calculate his weight now, so can you help him?

### Input

The first line gives two integers, N and M, representing the days lcy experienced and the weight of the first day.(n≤104,m≤1010000)

Then n lines followed.

Each line contains two integers x and y.(y≤1010000)

When x equals 1, it means that LCY’s current weight is y heavier than the previous day.

When x equals 2, it means that LCY’s current weight is y lighter than the previous day.

When x equals 3, it means that LCY’s current weight is y times heavier than the previous day.

Ensure LCY’s weight is always less than 1010000

### Output

Output a single line represents the weight after n days of LCY

## Prepare for CET-6（字符串，字典树Trie）

In order to prepare the CET-6 exam, LCY is reciting English words recently. Because he is already very clever, he can only recite n words to get full marks. He is going to memorize K words every day. But he found that if the length of the longest prefix shared by all the strings in that day is a**i, then he could get a**i laziness value. The lazy LCY must hope that the lazier the better, so what is the maximum laziness value he can get?

For example:

The group {RAINBOW, RANK, RANDOM, RANK} has a laziness value of 2 (the longest prefix is ‘RA’).

The group {FIRE, FIREBALL, FIREFIGHTER} has a laziness value of 4 (the longest prefix is ‘FIRE’).

The group {ALLOCATION, PLATE, WORKOUT, BUNDLING} has a laziness value of 0 (the longest prefix is ‘’).

### Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with a line containing the two integers N and K. Then, N lines follow, each containing one of Pip’s strings.

2≤N≤105

2≤KN

Each of Pip’s strings contain at least one character.

Each string consists only of letters from A to Z.

K divides N.

The total number of characters in Pip’s strings across all test cases is at most .

### Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum sum of scores possible.

## Computer Games（博弈论）

LCY is playing games with his computer at home. Each playing card has two attributes: A**i and B**i, LCY and his computer take turns selecting playing cards,with LCY going first. In each turn, a player can select one card, as long as that playing card either has an A**i greater than each of the all soldiers selected so far, or has a B**i greater than each of the all cards selected so far.

To be precise:

let A**i and B**i be the values for the i-th cards, for i from 1 to N, and let S be the set of cards that have been selected so far. Then a player can select card x if and only if at least one of the following is true:

A**x>A*sfor all *s in S

B**x>B**s for all s in S

If no selection can be made, then the selection process ends and the player with more playing cards win. LCY wants to select more cards and win the game. If both players play optimally to accomplish their goals, can LCY succeed?

### 输入格式

The first line of each case contains a positive integer N, the number of cards. N more lines follow; the i-th of these line contains two integers Ai and Bi, indicating the values of the i-th cards.(N≤4000,0≤A**i,B*i*≤10000)

### 输出格式

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is YES or NO, indicating whether LCY can guarantee that he selects more cards than computer, even if computer plays optimally to prevent this.

### 题目大意

1、玩家先手，所以只要保证到电脑拿牌的时候无法再拿的时候就一定赢；

2、无法再拿的条件：当前牌堆中的排的两面都不存在比已拿牌堆中更大的牌；

3、对AI和BI排序，如果存在同一张牌的正反面的次序相同，就一定能赢。

## sort（签到题，排序）

Xiaoming is tired of asking for help. This time he wants to test you.

He gave you N integers. Please find the number with the largest M.

### 输入格式

The first row has two numbers N, M (0<mn≤1000000).

The second line contains N integers that are different and are all in the interval [- 500000,500000].

### 输出格式

Output the number of the first M in the order of large to small.

## lcy eats biscuits（图的遍历，搜索回溯剪枝）

In order to grow nine abdominal muscles, LCY began to eat all the N biscuits in his room, but LCY didn’t like walking, because walking would cause his abdominal muscles to become smaller.How long does he have to run to get n biscuits. At the beginning, LCY is at (0,0)

### Input

The first line is a positive integer N.(N≤14)

Next, there are 2 real numbers in each line, representing the coordinates of the ith biscuits.(−10000≤x**i,y*i*≤10000)

The distance formula between two points is√(x1−x2)2+(y1−y2)2

### Output

A number, representing the minimum distance to run, with 2 decimal places reserved.

### 题目大意

1、对于这种两两之间都是可走的就无需建图，直接算会方便的多。

2、注意递归结束条件，根据开始条件的不同而不同。

3、当前的距离已经比之前最小距离大的时候，无需进行下一步运算。（剪枝）