题解:P13386 [GCJ 2011 Finals] Google Royale
ini2015_____ · · 题解
恐怖结论题。
假设这个人叫 Alice 好了。
首先你发现,当游戏结束的时候,Alice 手上的钱数必定是
然后你再发现,Alice 玩游戏的过程中,每一轮的期望收益都是
然后就有一个很深刻的想法是,记获胜的概率为
于是,这里
于是我们的策略变成了让
这之后所有的推导都比较自然了。
这样你发现所有操作的目的就变成了,我需要获得更多的钱,然后一波梭哈,把所有钱都输掉,来让
我们提出对最优策略的刻画是,要么一波全部梭哈,要么稳扎稳打。
形式化地说,要么选择
::::info[证明]
我们的策略可以归纳成
我们证明只存在
假设
假如
假设
| 那么所有 |
|---|
| 然后我们只需要知道哪些 |
记
首先
对于一个
::::info[证明]
考虑假设
而假如我只在
| 于是这个结论就对了。 |
|---|
考虑对一个
::::info[证明]
反证法,假设
| 记 |
|---|
| 于是可能成为梭哈点的位置只有 |
考虑
然后考虑第一问怎么算。
对一个位置,记在这个位置上成功过关的概率是
同时
由高中数学的熟知结论,
于是对于下一个梭哈点
然后考虑第二问,假如
假如
做完了,时间复杂度是
#include<bits/stdc++.h>
#define db double
#define ld long double
#define ll long long
#define ull unsigned long long
#define bint __int128
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define pii pair<int,int>
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define CheckSpace() cerr<<"Space used: "<<abs((&vst)-(&ved))/1024/1024<<" MB"<<endl
#define CheckTime() cerr<<"Time used: "<<(ted-tst)/1000.0<<" s"<<endl
using namespace std;
mt19937_64 rnd(time(0));
db tst; bool ved;
inline int ret();
inline char gc(){
constexpr int S=1<<23;
static char buf[S],*p1=buf,*p2=buf;
return (p1==p2&&(p2=(p1=buf)+fread(buf,1,S,stdin),p1==p2)?EOF:*p1++);
}
inline ll read(){
ll a=0,b=0;char c=gc();
while(c<'0'||c>'9')b^=(c=='-'),c=gc();
while(c>='0'&&c<='9')a=a*10-48+c,c=gc();
return b?-a:a;
}
inline int reads(string& s){
char c=gc(); s='~';
while(!isgraph(c))c=gc();
while(isgraph(c))s.pb(c),c=gc();
return s.size()-1;
}
inline void write(bint x,int o=1){
if(x<0)putchar('-'),x=-x;
if(x<10)putchar(x+'0');
else write(x/10,0),putchar(x%10+'0');
if(o)putchar('\n');
}
int TestCase; ll A,M,V;
// A : money you have at the beginning
// M : the limit to bet
// V : the goal
ll calc(ll x){
// the money you have when you lose
ll b=x;
while(b<=M)
x-=b,b<<=1;
return x;
}
vector<ll> S,T;
map<ll,ld> pn;
ld Q(ll x){
ld z=1; ll b=x;
while(b<=M)z=z*0.5,b<<=1;
return 1-z;
}
db P(ll x){
if(x<=0)return 0;
if(pn.count(x))return pn[x];
ll las=V;
for(auto t:T){
if(t<x && x<las)
return (pn[las]-pn[t])*(x-t)/(las-t)+pn[t];
las=t;
}
}
set<ll> W;
void solve(){
A=read(),M=read(),V=read();
S.clear(),T.clear(); W.clear();
ll mn=1;
for(int i=60;~i;i--)if(M>>i){
ll t=M>>i;
if(2*t>V)continue;
if(calc(t)<=mn)W.insert(t);
if(calc(t)< mn)S.pb(t),T.pb(t),mn=calc(t);
}
reverse(T.begin(),T.end());
ll las=V; pn.clear(),pn[V]=1;
for(auto v:T){
if(2*v>=las)pn[v]=Q(v)*P(2*v);
else{
ld c4=Q(v); c4=1/c4;
pn[v]=P(las)*v/(c4*(las-v)-(las-2*v));
}
las=v;
}
static int idx=0; ++idx;
printf("Case #%d: %.9lf ",idx,P(A));
if(W.find(A)!=W.end())printf("%lld\n",A);
else{
ll mn=min(M,V-A);
for(auto t:S)chkmin(mn,abs(t-A));
printf("%lld\n",mn);
}
}
bool vst; int main(){ tst=clock();
TestCase=read();
while(TestCase--)solve();
return ret();
}
inline int ret(){
db ted=clock();
CheckSpace();
CheckTime();
return 0;
}
// Think twice,code once
:::: ::::info[附件:人生哲理]
| 输的越多,赢的概率越大!!! |
|---|