版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
title: "题解 - [Atcoder ABC 126] (C - F)" categories:
Snuke has a fair $N$-sided die that shows the integers from $1$ to $N$ with equal probability and a fair coin. He will play the following game with them:
You are given $N$ and $K$. Find the probability that Snuke wins the game.
Input is given from Standard Input in the following format:
$N\ K$
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most $10^{-9}$.
3 10
0.145833333333
Thus, the probability that Snuke wins is $\frac{1}{48}+\frac{1}{24}+\frac{1}{12}=\frac{7}{48}≃0.1458333333$.
100000 5
0.999973749998
式子还蛮好推的, 照着做就行
就是注意下精度, 本题要求到 1e-9
当然搞整除分块也不是不可以
We have a tree with $N$ vertices numbered $1$ to $N$. The $i$-th edge in the tree connects Vertex ui and Vertex $v_i$, and its length is $w_i$. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:
Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
Input is given from Standard Input in the following format:
$\begin{matrix} N\ u_1&v_1&w_1\ u_2&v_2&w2\ \vdots\ u{N-1}&v{N-1}&w{N-1} \end{matrix}$
Print a coloring of the vertices that satisfies the condition, in $N$ lines. The $i$-th line should contain $0$ if Vertex $i$ is painted white and $1$ if it is painted black.
If there are multiple colorings that satisfy the condition, any of them will be accepted.
3
1 2 2
2 3 1
0
0
1
5
2 5 2
2 3 10
1 3 8
3 4 2
1
0
1
0
1
如果边权为偶数, 则两端点同色; 如果边权为奇数, 则两端点异色
There are $N$ cards placed face down in a row. On each card, an integer $1$ or $2$ is written.
Let $A_i$ be the integer written on the $i$-th card.
Your objective is to guess $A_1,A_2,...,A_N$ correctly.
You know the following facts:
You are a magician and can use the following magic any number of times:
Magic: Choose one card and know the integer $A_i$ written on it. The cost of using this magic is $1$.
What is the minimum cost required to determine all of $A_1,A_2,...,A_N$?
It is guaranteed that there is no contradiction in given input.
Input is given from Standard Input in the following format:
$\begin{matrix} N&M\ X_1&Y_1&Z_1\ X_2&Y_2&Z_2\ \vdots\ X_M&Y_M&Z_M \end{matrix}$
Print the minimum total cost required to determine all of $A_1,A_2,...,A_N$.
3 1
1 2 1
2
You can determine all of $A_1,A_2,A_3$ by using the magic for the first and third cards.
6 5
1 2 1
2 3 2
1 3 3
4 5 4
5 6 5
2
100000 1
1 100000 100
99999
一眼并查集, 没啥好说的
Construct a sequence $a= {a_1, a2, ..., a{2^{M+1}}}$ of length $2^{M+1}$ that satisfies the following conditions, if such a sequence exists.
Input is given from Standard Input in the following format:
$M\ K$
If there is no sequence $a$ that satisfies the condition, print -1
.
If there exists such a sequence $a$, print the elements of one such sequence $a$ with spaces in between.
If there are multiple sequences that satisfies the condition, any of them will be accepted.
1 0
0 0 1 1
For this case, there are multiple sequences that satisfy the condition.
For example, when $a = {0,0,1,1}$, there are two pairs $(i, j) (i<j)$ such that $a_i=a_j$: $(1,2)$ and $(3,4)$. Since $a_1\ xor\ a_2=0$ and $a_3\ xor\ a_4=0$, this sequence $a$ satisfies the condition.
1 1
-1
No sequence satisfies the condition.
5 58
-1
No sequence satisfies the condition.
首先我们注意到
$$ \forall k\in\mathbb{N}^+,\bigoplus_{i=0}^{2^k-1}i=0 $$
用数学归纳法证明即可, 或者考虑 Sierpinski 三角形
其次我们知道异或的逆运算是异或, 所以我们可以这样构造:
其余情况我们可以这样构造
0 1 ... K-1 K+1 ... 2^M-2 2^M-1 K 2^M-1 2^M-2 ... K+1 K-1 ... 1 0 K