当前位置:网站首页>[acnoi2022] no way without guessing

[acnoi2022] no way without guessing

2022-06-23 04:37:00 OneInDark

tell the truth c n b l o g s \rm cnblogs cnblogs Just like a place to write a blog . C S D N \rm CSDN CSDN What is it


subject

Background
Follow OUYE \textsf{OUYE} OUYE Learn together O I \rm OI OI It is a gamble in life . Poor thing is , No casino will let you win more and lose less .

Title Description
Do you have x    ( 0 ⩽ x < 1 ) x\;(0\leqslant x<1) x(0x<1) money , You can gamble , The amount is any real number y y y, But you need { y i } \{y_i\} { yi} Monotonous . if x ⩾ 1 x\geqslant 1 x1 You win , It's impossible to achieve and lose .

Gambling rules : cast y y y money , Yes p p p The probability is 2 y 2y 2y money , Yes ( 1 − p ) (1{-}p) (1p) Probability is lost . Guarantee p < 1 2 p<\frac{1}{2} p<21 .

Find the probability of winning under the optimal strategy . Yes 998244353 998244353 998244353 Take the mold output .

Data range and tips
x = a 1 b 1 ,    p = a 2 b 2 x=\frac{a_1}{b_1},\;p=\frac{a_2}{b_2} x=b1a1,p=b2a2, Yes a 1 < b 1 ⩽ 1 0 6 a_1<b_1\leqslant 10^6 a1<b1106 And 2 a 2 < b 2 ⩽ 1 0 6 2a_2<b_2\leqslant 10^6 2a2<b2106 .

Ideas

There are no examples , I will not get a cent . With the example , The score is still low . Get out of the math problem O I \rm OI OI

Solve first b 1 = 2 k b_1=2^k b1=2k, That is to say x x x Is a finite decimal under binary . It is impossible not to guess the conclusion .

Conclusion : Every time x x x The last one under binary 1 1 1 Bet on the corresponding number .

prove : First, relax the conditions , Don't ask for the amount of gambling not to drop . We will prove , In this looser decision tree , This is the optimal strategy .

The following is the proof of the solution . There are some places I can't quite understand , The place in doubt will be marked with .

Make c ( s ) c(s) c(s) by s s s Binary system 1 1 1 The number of , f ( x , n )    ( x ∈ N ) f(x,n)\;(x\in\Bbb N) f(x,n)(xN) by x 2 n \frac{x}{2^n} 2nx become 1 1 1 Probability . Let's assume that the amount of gambling can only be 2 − n 2^{-n} 2n Multiple , So this is equivalent to x → 2 n x\to 2^n x2n Bet the whole amount each time . remember q = 1 − p q=1-p q=1p Then there is a recurrence
f ( x , n ) = p ⋅ f ( ⌈ x 2 ⌉ , n − 1 ) + q ⋅ f ( ⌊ x 2 ⌋ , n − 1 ) f(x,n)=p\cdot f\left(\left\lceil\frac{x}{2}\right\rceil,n{-}1\right)+q\cdot f\left(\left\lfloor{x\over 2}\right\rfloor,n{-}1\right) f(x,n)=pf(2x,n1)+qf(2x,n1)

because 2 ∤ x 2\nmid x 2x I was gambling , 2 ∣ x 2\mid x 2x Time is shifting .

It's not hard to find out , This is actually a probability that l o w b i t \rm lowbit lowbit Carry or disappear . We enumerate where b i t \rm bit bit On “ Let go ” 了 , Set to i i i . about lcp ( x , i ) \text{lcp}(x,i) lcp(x,i) Part of , If both are 1 1 1, It means you missed it , It must be carried forward in one breath ; If both are 0 0 0, Although I didn't miss , For final carry , The following must be carried . about lcp \text{lcp} lcp The latter , if x x x by 0 0 0 and i i i by 1 1 1 Then there is no carry possibility , The opposite is always possible . So the back b i t \rm bit bit It doesn't matter . It is not difficult to find that this is i < x i<x i<x The judgment of the , thus
f ( x , n ) = ∑ i = 0 x − 1 q c ( i ) p n − c ( i ) f(x,n)=\sum_{i=0}^{x-1}q^{c(i)}p^{n-c(i)} f(x,n)=i=0x1qc(i)pnc(i)

The above text is a way of understanding ; Mathematical induction can also prove it .

Next, just prove ∀ k ∈ [ 0 , x ] ∩ Z \forall k\in[0,x]\cap\Bbb Z k[0,x]Z Yes f ( x , n ) ⩾ p ⋅ f ( x + k , n ) + q ⋅ f ( x − k , n ) f(x,n)\geqslant p\cdot f(x{+k},n)+q\cdot f(x{-}k,n) f(x,n)pf(x+k,n)+qf(xk,n) . Press : Something should be summed up here , Similar to the shortest circuit , Just verify that the distance label cannot be relaxed . But the shortest path can be as follows “ The number of shortest sides ” inductive , And you ?
p ( f ( x + k , n ) − f ( x , n ) ) ⩽ q ( f ( x , n ) − f ( x − k , n ) ) ⇔ ∑ i = 0 k − 1 q c ( i + x ) p n − c ( i + x ) + 1 ⩽ ∑ i = 1 k q c ( x − i ) + 1 p n − c ( x − i ) \begin{aligned} p(f(x{+}k,n)-f(x,n))&\leqslant q(f(x,n)-f(x{-}k,n))\\ \Leftrightarrow\sum_{i=0}^{k-1}q^{c(i+x)}p^{n-c(i+x)+1}&\leqslant\sum_{i=1}^{k}q^{c(x-i)+1}p^{n-c(x-i)} \end{aligned} p(f(x+k,n)f(x,n))i=0k1qc(i+x)pnc(i+x)+1q(f(x,n)f(xk,n))i=1kqc(xi)+1pnc(xi)

We prove a super unequal relation : There is bijection f ( t ) : [ x , x + k ) ↦ [ x − k , x ) f(t):[x,x{+}k)\mapsto[x{-}k,x) f(t):[x,x+k)[xk,x) bring
q c ( i ) p n − c ( i ) + 1 ⩽ q c ( f ( i ) ) + 1 p n − c ( f ( i ) ) q^{c(i)}p^{n-c(i)+1}\leqslant q^{c(f(i))+1}p^{n-c(f(i))} qc(i)pnc(i)+1qc(f(i))+1pnc(f(i))

That is, each item is smaller . I dare not put math problems in high school like this . It is equivalent to
q c ( i ) − c ( f ( i ) ) − 1 ⩽ p c ( i ) − c ( f ( i ) ) − 1 ⇐ c ( i ) − c ( f ( i ) ) − 1 ⩽ 0 q^{c(i)-c(f(i))-1}\leqslant p^{c(i)-c(f(i))-1}\Leftarrow c(i)-c(f(i))-1\leqslant 0 qc(i)c(f(i))1pc(i)c(f(i))1c(i)c(f(i))10
because q > p q>p q>p Well . The simplest way of thinking is , Make f ( i ) f(i) f(i) by i i i The result of removing a binary bit . Can it be done ?

set up s = 2 ⌈ log ⁡ 2 k ⌉ s=2^{\lceil\log_2 k\rceil} s=2log2k, Yes i ∈ [ x − k + s ,    x + k ) i\in[x{-}k{+}s,\;x{+}k) i[xk+s,x+k) Regulations f ( i ) = i − s f(i)=i-s f(i)=is . There is one left [ x , x + s − k ) ↦ [ x + k − s , x ) [x,x{+}s{-}k)\mapsto[x{+}k{-}s,x) [x,x+sk)[x+ks,x) Need to construct . Continuous recursion can complete the construction . Therefore, the conclusion is tenable .

□ \square

The other two are posted below “ prove ”, For reference only .

Proof of rain rabbit and sand duck

If you don't gamble l o w b i t \rm lowbit lowbit, Bet higher b i t \rm bit bit, After that l o w b i t \rm lowbit lowbit You can't bet , Rounding does not come up , It's useless. . If you bet lower b i t \rm bit bit, In the end, either l o w b i t \rm lowbit lowbit Carry or not carry , Better bet .

□ \square

The proof of Master Zhang

Basic strategy : If the amount of money ⩽ 1 2 \leqslant\frac{1}{2} 21 Just all-in \text{all-in} all-in, Or bet ( 1 − x ) (1{-}x) (1x) . because p < 1 2 p<\frac{1}{2} p<21 So I expect that if I bet too much, I will only lose money , Better put all your eggs in one basket . We admit that it is optimal . Call it “ Basic strategy ”.

Then we prove that it is equivalent to another strategy : remember f ( x ) f(x) f(x) For the current x x x Money is the bet of choice , be
f ( x ) = { 1 2 ( x = 1 2 ) 1 4 − ∣ x − 1 4 ∣ ( x < 1 2 ) 1 4 − ∣ x − 3 4 ∣ ( x > 1 2 ) f(x)=\begin{cases} \frac{1}{2} & (x=\frac{1}{2})\\ \frac{1}{4}-|x-\frac{1}{4}| & (x<\frac{1}{2})\\ \frac{1}{4}-|x-\frac{3}{4}| & (x>\frac{1}{2}) \end{cases} f(x)=2141x4141x43(x=21)(x<21)(x>21)

If you will f ( x ) f(x) f(x) Draw the image of , So it was “ peak ” The shape of the , And this change is to make two “ hillside ” Change again to “ peak ”, Only a single point on the top of the mountain .

The proof process is vigorously developed . Here is to 1 4 < x < 1 2 \frac{1}{4}<x<\frac{1}{2} 41<x<21 For example .
g ( x ) = p ⋅ g ( 1 2 ) + q ⋅ g ( 2 x − 1 2 ) = p 2 + q p ⋅ g ( 4 x − 1 ) ( 0.25 < x < 0.5 ) \begin{aligned} g(x) &=p\cdot g\left(\frac{1}{2}\right)+q\cdot g\left(2x-\frac{1}{2}\right)\\ &=p^2+qp\cdot g(4x-1)\quad(0.25<x<0.5) \end{aligned} g(x)=pg(21)+qg(2x21)=p2+qpg(4x1)(0.25<x<0.5)

Note that the second line uses “ Basic strategy ” an , all-in \text{all-in} all-in Result . Press : It feels like an obscure induction , namely “ Other locations used this strategy to fit the same winning rate , Therefore, it can be directly expanded by the winning rate equation of the original strategy ”. But it's hard to generalize .

Or say , I proved “ Adjust the first step strategy to get the same winning rate ”, And each step is equivalent to the first step , So every step can be adjusted ? It's always strange to say .

The result of direct expansion is
g ( x ) = p ⋅ g ( 2 x ) = p 2 + p q ⋅ g ( 4 x − 1 ) g(x)=p\cdot g(2x)=p^2+pq\cdot g(4x-1) g(x)=pg(2x)=p2+pqg(4x1)

So it works . Empathy , We can transform “ hillside ” Replace with “ peak ”.

It is not difficult to find out that in the end f ( s 2 k ) = 1 2 k    ( 2 ∤ s ) f(\frac{s}{2^k})=\frac{1}{2^k}\;(2\nmid s) f(2ks)=2k1(2s) . This is every bet l o w b i t \rm lowbit lowbit Well .

□ \square

use d p \tt dp dp Rewrite the above procedure : f i , 0 / 1 f_{i,0/1} fi,0/1 It's the second time at present i i i position , Whether there is a carry winning probability after . The transition is linear .

If at present b i t \rm bit bit by 0 0 0, Then it is transferred to
f i = ( 1 0 q p ) f i − 1 f_i= \begin{pmatrix} 1 & 0\\ q & p \end{pmatrix} f_{i-1} fi=(1q0p)fi1

among f i = ( f i , 0 f i , 1 ) f_i=\begin{pmatrix}f_{i,0}\\f_{i,1}\end{pmatrix} fi=(fi,0fi,1) . This transfer will not be discussed in detail , Just be patient .

If at present b i t \rm bit bit by 1 1 1, Then it is transferred to
f i = ( q p 0 1 ) f i − 1 f_i= \begin{pmatrix} q & p\\ 0 & 1 \end{pmatrix} f_{i-1} fi=(q0p1)fi1

about b i = 2 n b_i=2^n bi=2n The situation of , We have O ( n ) \mathcal O(n) O(n) It's solved . otherwise x x x It's an infinite circular decimal .

obviously x x x The length of the loop section of does not exceed b b b . Let the matrix of a single cyclic node be B B B, The matrix of the non pure cyclic part is A A A . Then we only need to solve
lim ⁡ n → + ∞ B n A ( 0 1 ) \lim_{n\to+\infty}B^{n}A \begin{pmatrix} 0\\ 1 \end{pmatrix} n+limBnA(01)

The general method is probably diagonalization . But in this question B B B Is a very recurrent Markov matrix , The steady state can be solved directly . Notice the line vector !

Code

#include <cstdio>
#include <algorithm> // Almighty XJX yyds!!
#include <cstring> // oracle: ZXY yydBUS!!!
#include <cctype> // Huge Egg Dog ate me!!!
using llong = long long;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
# define rep0(i,a,b) for(int i=(a); i!=(b); ++i)
inline int readint(){
    
	int a = 0, c = getchar(), f = 1;
	for(; !isdigit(c); c=getchar()) if(c == '-') f = -f;
	for(; isdigit(c); c=getchar()) a = a*10+(c^48);
	return a*f;
}

const int MOD = 1e9+7;
inline llong qkpow(llong b, int q){
    
	llong a = 1;
	for(; q; q>>=1,b=b*b%MOD) if(q&1) a = a*b%MOD;
	return a;
}

struct Matrix{
    
	int a00, a01, a10, a11;
	Matrix operator * (const Matrix &b) const {
    
		Matrix c;
		c.a00 = int((llong(a00)*b.a00+llong(a01)*b.a10)%MOD);
		c.a01 = int((llong(a00)*b.a01+llong(a01)*b.a11)%MOD);
		c.a10 = int((llong(a10)*b.a00+llong(a11)*b.a10)%MOD);
		c.a11 = int((llong(a10)*b.a01+llong(a11)*b.a11)%MOD);
		return c;
	}
	static Matrix I(){
    
		Matrix c; c.a00 = c.a11 = 1;
		c.a01 = c.a10 = 0; return c;
	}
	Matrix bite(){
    
		Matrix c;
		if(a00 != 1){
    
			// (a00-1)*x+a10*y = 0
			// x+y = 1 => (a00-1-a10)*x+a10 = 0
			c.a00 = c.a10 = int(qkpow(1+a10+MOD-a00,MOD-2)*a10%MOD);
			c.a01 = c.a11 = 1+MOD-c.a00; // Markov
		}
		else{
    
			// a01*x+(a11-1)*y = 0
			// x+y = 1 => (a11-1-a01)*y+a01 = 0
			c.a01 = c.a11 = int(qkpow(1+a01+MOD-a11,MOD-2)*a01%MOD);
			c.a00 = c.a10 = 1+MOD-c.a11;
		}
		return c;
	}
};
Matrix mat[2];

const int MAXB = 1000000;
int pos[MAXB]; bool bit[MAXB];
int main(){
    
	for(int T=readint(),a,b,p; T; --T){
    
		a = readint(), b = readint(), p = readint();
		p = int(qkpow(readint(),MOD-2)*p%MOD);
		mat[0].a00 = 1, mat[0].a01 = 0;
		mat[0].a10 = 1+MOD-p, mat[0].a11 = p;
		mat[1].a00 = 1+MOD-p, mat[1].a01 = p;
		mat[1].a10 = 0, mat[1].a11 = 1;
		memset(pos, -1, b<<2);
		int st = 0, ed = 0;
		for(int i=0; true; ++i){
    
			if(~pos[a]){
     // cycle found
				st = pos[a], ed = i; break;
			}
			pos[a] = i; // record
			if((a<<=1) >= b)
				a -= b, bit[i] = true;
			else bit[i] = false;
		}
		Matrix ddg = Matrix::I();
		rep0(i,st,ed) ddg = mat[bit[i]]*ddg;
		ddg = ddg.bite(); // infinite power
		drep(i,st-1,0) ddg = ddg*mat[bit[i]];
		printf("%d\n",ddg.a01);
	}
	return 0;
}
原网站

版权声明
本文为[OneInDark]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206222302063331.html