# | User | Rating |
---|---|---|
1 | jiangly | 3977 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3483 |
8 | hos.lyric | 3381 |
9 | gamegame | 3374 |
10 | heuristica | 3358 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | -is-this-fft- | 162 |
3 | Um_nik | 161 |
4 | atcoder_official | 159 |
5 | djm03178 | 157 |
5 | Dominater069 | 157 |
7 | adamant | 154 |
8 | luogu_official | 152 |
8 | awoo | 152 |
10 | TheScrasse | 148 |
This is my solution for 2040E - Control of Randomness. It passed the tests, but I’m not sure whether deriving the DP formula in this way (splitting the min, solving the equation, and then putting the min back) is rigorous.
More formally, if we have $$$x_0$$$ is the only number that satisfies $$$x_0=f(x_0)$$$, and so do $$$x_1$$$ and $$$g(x_1)$$$, can we say that $$$x=h(f(x),g(x))\Leftrightarrow x=h(x_0,x_1)$$$? What if $$$h(x,y)=\min(x,y)$$$?
We consider dynamic programming. Let $$$\mathrm{dp}_{i,j,0/1}$$$ represent the expected number of steps when currently at node $$$i$$$ with $$$j$$$ coins and about to take an even/odd step. To simplify the formulation: - Define $$$\mathrm{sc}_i := \text{number of children of } i, p_i := \text{parent of } i$$$. - The initial condition is $$$\mathrm{dp}_{1,j,0/1} = 1$$$.
Odd steps are straightforward:
From the problem description:
The "not to pay" case involves both the parent and children, making it more complex. However, observe that:
This implies that for the "not to pay" case:
Reorganizing:
Thus:
考虑 dp,设 $$$\mathrm{dp}_{i,j,0/1}$$$ 表示目前走到节点 $$$i$$$,有 $$$j$$$ 块钱,将要走第偶数 / 奇数步的答案。为了方便表述,定义
初始情况显然是
奇数步也很好递推:
对于偶数步,根据题目可得:
不付钱的情况与父亲和儿子都有关,比较难搞。但是不难注意到
也就是说,对于不付钱的情况:
所以
https://arxiv.org/pdf/2411.19826
Amazed by the perseverance, intellect, and exploratory spirit of mathematicians.
There are some functions $$$T_y$$$, which are defined as:
Find $$$y$$$ (s) so that the order of $$$\lim_{x\rightarrow+\infty}T_y(x)$$$ is minimized.
When to use this:
You should have these files below in the same folder:
1.cpp (or other languages): Your code that got Wrong answer.
For standard problems: std.cpp (or other languages): Code that will not output the wrong answer
For special judge problems: checker.cpp (or other languages): To check if your output is right, returns 0 in main()
if wrong, and returns 1 if correct
gen_data.cpp (or other languages): To generate random input data
hacker.sh/bat (or other languages that can run bash/cmd command): main program
Details of implementation:
For gen_data.cpp
: use mt19937
and chrono::high_resolution_clock().now().time_since_epoch().count()
to generate random integer instead of rand()
and srand(time(0))
. Tutorial of mt19937
For Windows, standard problems, the hacker.cpp
: (sorry for not knowing much about batch)
#include <bits/stdc++.h>
using namespace std;
int main() {
// ↓ compile your code here ↓
// ↑ compile your code here ↑
int i = 0;
do {
system("gen_data.exe > in.txt");
system("1.exe < in.txt > out.txt");
system("std.exe < in.txt > ans.txt");
cout << ++i << endl;
} while (!system("fc out.txt ans.txt"));
cout << "in: " << endl;
system("type in.txt");
cout << "ans: " << endl;
system("type ans.txt");
cout << "out: " << endl;
system("type out.txt");
return 0;
}
For Windows, special judge problems, the hacker.cpp
:
#include <bits/stdc++.h>
using namespace std;
int main() {
// ↓ compile your code here ↓
// ↑ compile your code here ↑
int i = 0;
do {
system("gen_data.exe > in.txt");
system("1.exe < in.txt > out.txt");
cout << ++i << endl;
} while (system("checker.exe"));
cout << "in: " << endl;
system("type in.txt");
cout << "out: " << endl;
system("type out.txt");
return 0;
}
For Linux/macOS, standard problems, the hacker.sh
:
if ! [ -e 1.cpp ]; then
echo "file doesn't exist"
exit
fi
# ↓ compile your code here ↓
shopt -s expand_aliases
alias comp_cpp="g++ -O3 -Wall -Wextra -Wshadow -std=c++14"
comp_cpp std.cpp -o std.out
comp_cpp 1.cpp -o 1.out
comp_cpp gen_data.cpp -o gen_data
# ↑ compile your code here ↑
i=0
while true
do
./gen_data > in
./std.out < in > ans
./1.out < in > out
diff -b -B ans out > dif
if [ -s ./dif ]; then
echo $i
echo "hack:"
cat in
echo "ans:"
cat ans
echo "out:"
cat out
rm -f 1.out bruteforce.out gen_data dif
exit
else
let i++
echo $i
fi
done
For Linux/macOS, special judge problems, the hacker.sh
:
if ! [ -e 1.cpp ]; then
echo "file doesn't exist"
exit
fi
# ↓ compile your code here ↓
shopt -s expand_aliases
alias comp_cpp="g++ -O3 -Wall -Wextra -Wshadow -std=c++14"
comp_cpp 1.cpp -o 1.out
comp_cpp gen_data.cpp -o gen_data
comp_cpp checker.cpp -o checker
# ↑ compile your code here ↑
i=0
while true
do
./gen_data > in
./1.out < in > out
diff -b -B ans out > dif
if [ ! checker ]; then
echo $i
echo "hack:"
cat in
echo "out:"
cat out
rm -f 1.out bruteforce.out gen_data dif
exit
else
let i++
echo $i
fi
done
The main usage of this is to generate small-scale data for debugging.
It's bad for training
Name |
---|