# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14708 | Longest double palindrome |
|
14711 | 3D Bingo Cube |
|
14712 | Compute Cosine Function with a Series |
|
14713 | Third Closest Point to the Origin (3D) |
|
14714 | Tic-Tac-Toe |
|
Description
# HARD!!! DO OTHER PROBLEM FIRST. #
A palindrome (回文) is a sequence of integers of length at least 1 that reads the same forwards and backwards.
For example:
-
(1, 3, 5, 3, 1), (1, 2, 2, 1), and (1) are all palindromes.
If we concatenate two palindromes, we obtain a double palindrome.
For example:
-
(1, 3, 5, 3, 1) + (1, 2, 2, 1) = (1, 3, 5, 3, 1, 1, 2, 2, 1)
-
(1, 3, 5, 3, 1) + (1) = (1, 3, 5, 3, 1, 1)
are both double palindromes.
Now, given a sequence of integers of length n, please find the longest double palindrome contained in it.
If there are multiple with the same maximum length, output the one that appears last.
(Hint
-
You may need to use nested for-loops to check all possible subsequences of the sequence.
-
You may write a a loop to check whether a subsequence is a palindrome.
-
To form a double palindrome, split the subsequence into two parts and check if both parts are palindromes.
-
Keep track of the longest length found, and if there are multiple with the same length, choose the one that appears last.
)
Input
-
The first line contains one integer n (2 ≤ n ≤ 100), the length of the sequence.
-
The second line contains n integers, representing the sequence.
Output
- Print the longest double palindrome as a sequence of integers separated by spaces.
- If multiple answers exist, print the one appearing last in the sequence.
- Ensure that the output, including formatting, exactly matches the provided samples.
Sample Input Download
Sample Output Download
Discuss
Description
!! Challenging
You are given an n x n x n cube.
Each small cell of the cube contains a unique integer from 1 to n3
A sequence of n3 numbers will then be drawn one by one.
Whenever a number is drawn, it is marked in the cube.
If, at any point, all cells along a straight line are marked, we say “bingo.”
A straight line may be:
-
A row along the x-axis,
-
A column along the y-axis,
-
A line along the z-axis,
-
A diagonal on one of the cube’s faces,
-
Or one of the four main space diagonals connecting two opposite corners of the cube.
Your task is to determine which drawn number first causes a “bingo.”
Input
-
The first line contains an integer n (0 < n ≤ 10)
-
The following n3 integers describe the cube’s contents in row-major order.
-
That is, the numbers are listed layer by layer, row by row, and column by column.
-
-
The next n3 integers represent the sequence of numbers being drawn, in order.
-
For readability, the numbers may be given with n numbers per line.
-
Example Walkthrough (Sample Input 1)
3
2 18 4
3 1 20
14 6 12
7 21 15
6 9 17
19 5 22
8 23 12
1 3 5
7 9 11
13 15 17
19 21 23
25 27 2
4 6 8
10 12 14
16 18 20
22 24 26
-
First Line:
The integer3
tells us the cube size is 3×3×3.
That means the cube contains 33=27 cells, each filled with a unique number from 1 to 27. -
Next 27 Numbers (Cube Contents):
The following numbers describe how the cube is filled.
They are given in row-major order: layer by layer, row by row, left to right.For n=3, these 27 numbers form a 3×3×3 cube:
1 | 18 | 4 |
13 | 2 | 20 |
24 | 10 | 26 |
27 | 14 | 7 |
3 | 25 | 16 |
21 | 15 | 11 |
6 | 9 | 17 |
19 | 5 | 22 |
8 | 23 | 12 |
- Next 27 Numbers (Draw Sequence):
After the cube contents, the next block of numbers lists the draw order.
These are the numbers being drawn one by one, and whenever a number is drawn, the corresponding cell in the cube is marked.
The sequence here is:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 2 4 6 8 10 12 14 16 18 20 22 24 26
Output
Print a single integer: the first drawn number that causes a bingo.
Cube contents (layer by layer, row-major):
For example,
1 | 18 | 4 |
13 | 2 | 20 |
24 | 10 | 26 |
27 | 14 | 7 |
3 | 25 | 16 |
21 | 15 | 11 |
6 | 9 | 17 |
19 | 5 | 22 |
8 | 23 | 12 |
The sequence here is:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 2 4 6 8 10 12 14 16 18 20 22 24 26
As we mark numbers in this order, the cube first achieves bingo when 19 is drawn.
Sample Input Download
Sample Output Download
Discuss
Description
Write a program to compute cos(x) for a given real number x (in radians, 0≤x≤2π) using the Taylor series:
To ensure sufficient accuracy, use double precision floating-point arithmetic and sum the series up to n = 15 (i.e., include the terms for n=0,1,…,15).
For example, please perform this calculation
Information about factorial function:
- 0! = 1
-
(2n)!=1×2×3×⋯×(2n)
Notes:
-
Do not call a library cosine function to compute the answer; use the series definition.
-
For efficiency and numerical stability, update powers and factorials iteratively rather than recomputing them from scratch each term.
Input
Given real number x (in radians, 0≤x≤2π)
Output
Output: Print the result rounded to exactly 6 digits after the decimal point.
Sample Input Download
Sample Output Download
Discuss
Description
You are given n points in 3D space.
For each point (x,y,z)(x,y,z)(x,y,z) (in double precision), its distance to the origin is
Print the 1-based index (i.e., counting from 1) of the point that is the third closest to the origin.
Important: n can be very large, so you should not store all points before deciding. Process the input in a streaming fashion.
If multiple points have exactly the same distance, the one with the smaller index is considered closer.
Input
-
The first line contains an integer n (3 ≤ n ≤ 1_000_000)
-
Each of the next n lines contains three real numbers x y z (double), representing one point.
Output
Print a single integer — the index (1-based) of the point that is the third closest to the origin.
Sample Input Download
Sample Output Download
Discuss
Description
Write a program to play tic-tac-toe.
We use the numbers 1 to 9 to represent the nine squares of the tic-tac-toe board from top to bottom, left to right: 1 represents the top-left corner, and 9 represents the bottom-right corner.
The input is a single line containing the sequence of moves made by both players, up to 9 numbers.
If either player wins, output the last number placed by the winning player.
If the game ends in a draw, output 0.
Input
The sequence of moves made by both players, up to 9 numbers.
Ex. 6 4 2 7 5 9 3
Output
If either player wins, output the last number placed by the winning player.
If the game ends in a draw, output 0.
Ex. 0