Translation Notice
This article was machine-translated using DeepSeek-R1.
- Original Version: Authored in Chinese by myself
- Accuracy Advisory: Potential discrepancies may exist between translations
- Precedence: The Chinese text shall prevail in case of ambiguity
- Feedback: Technical suggestions regarding translation quality are welcomed
A - Div
Problem Statement
Two boys want to divide $N$ candies. How many ways are there to distribute them (each boy must get at least one candy)?
$1\le N\le 15$
Input Format
$N$
Output Format
Print the answer as an integer.
Sample
$N$ | Output |
---|---|
$2$ | $1$ |
$1$ | $0$ |
$3$ | $2$ |
Analysis
The problem reduces to splitting $N$ into two positive integers $A$ and $B$ (where $A+B$ and $B+A$ count as distinct). The possible pairs are:
$A$ | $B$ |
---|---|
$1$ | $N-1$ |
$2$ | $N-2$ |
$\dots$ | $\dots$ |
$N-1$ | $1$ |
This table has $N-1$ entries, so we directly output $N-1$. |
Code
|
|
B - Palindrome with leading zeros
Problem Statement
Given an integer $N$, can we prepend any number (including zero) of 0
s to its decimal representation to make it a palindrome?
$0\le N\le 10^9$
Input Format
$N$
Output Format
Print Yes
or No
.
Sample
$N$ | Output |
---|---|
$1210$ | Yes |
$777$ | Yes |
$123456789$ | No |
Analysis
If prepending zeros can make $N$ a palindrome, then trimming all trailing zeros from $N$ must also yield a palindrome. Thus, we trim trailing zeros and check if the resulting string is a palindrome.
Code
|
|
C - Compass Walking
Problem Statement
In a 2D plane, a person moves exactly $R$ units per step. What is the minimum steps needed to go from $(0,0)$ to $(X,Y)$?
Note: The distance between $(x_1, y_1)$ and $(x_2,y_2)$ is $\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$.
$1\le R\le 10^5$
$0\le X,Y\le 10^5$
$(X,Y)\ne(0,0)$
Input Format
$R~X~Y$
Output Format
Print the minimum number of steps.
Sample
$R$ | $X$ | $Y$ | Output |
---|---|---|---|
$5$ | $15$ | $0$ | $3$ |
$5$ | $11$ | $0$ | $3$ |
$3$ | $4$ | $4$ | $2$ |
Analysis
Let $d=\sqrt{X^2+Y^2}$ (Euclidean distance). The solution depends on:
- If $d = R$: 1 step.
- If $d < R$: 2 steps (two orthogonal steps form a hypotenuse).
- If $d > R$: $\lceil\frac{d}{R}\rceil$ steps.
Code
Precision issues were tricky, but using long double
worked.
|
|
D - Send More Money
Problem Statement
Given three lowercase strings $S_1,S_2,S_3$, assign each unique letter a distinct digit (0-9) such that $N_1 + N_2 = N_3$ when converted to numbers (no leading zeros). Output any solution or UNSOLVABLE
.
$1\le |S_1|,|S_2|,|S_3|\le 10$
Time Limit: 5 sec
Input Format
$S_1$
$S_2$
$S_3$
Output Format
Print $N_1$, $N_2$, $N_3$ on three lines, or UNSOLVABLE
.
Sample
$S_1$ | $S_2$ | $S_3$ | Output |
---|---|---|---|
a |
b |
c |
1 2 3 |
x |
x |
y |
1 1 2 |
p |
q |
p |
UNSOLVABLE |
Analysis
If the total unique letters exceed 10, output UNSOLVABLE
. Otherwise, brute-force all permutations of digit assignments (up to $10!$ possibilities) and validate.
Code
Using permutations for enumeration:
|
|
P.S. This code runs surprisingly fast… took only 109ms…
E - Unique Color
Problem Statement
Given a tree with $N$ vertices, each vertex has a color $C_i$. A vertex $x$ is good if:
- The shortest path from vertex $1$ to $x$ contains no duplicate colors (excluding $x$ itself).
Output all good vertices in ascending order.
$2\le N\le 10^5$
$1\le C_i\le 10^5$
Input Format
$N$
$C_1~\dots~C_N$
$A_1~B_1$
$\vdots$
$A_{N-1}~B_{N-1}$
Output Format
List all good vertices, one per line.
Analysis
Use DFS to track colors along the path. Maintain a used
array to check color uniqueness. Time complexity: $\mathcal O(N)$.
Code
|
|