QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661644 | #8037. Gambler's Ruin | MENDAX | WA | 1ms | 6032kb | C++20 | 1.0kb | 2024-10-20 17:15:02 | 2024-10-20 17:15:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
inline int read(){
int x=0,k=1;char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')k=-1;
c=getchar();
}
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*k;
}
const int N=1e6+5;
const double eps=1e-13;
double p[N];
int c[N];
int n;
double cal(double x){
int sx=0;
for(int i=1;i<=n;++i)if(p[i]*x>=1){
sx+=c[i];
}
double l=1,r=2;
int sy=0;
double m=sx*x;
while(l+eps<r){
int cy=0;
double y=(l+r)/2;
for(int i=1;i<=n;++i){
if(p[i]*x>=1)continue;
if((1-p[i])*y>=1)cy+=c[i];
}
if(cy*y-0.0001<m)l=y,sy=max(sy,cy);
else r=y-eps;
}
return sx+sy-sx*x;
}
void sol(){
n=read();
for(int i=1;i<=n;++i)cin>>p[i]>>c[i];
double l=1,r=2;
while(l+eps<r){
double lm=l+(r-l)/3,rm=r-(r-l)/3;
// cout<<lm<<' '<<rm<<endl;
// cout<<cal(lm)<<"?"<<cal(rm)<<endl;
if(cal(lm)<cal(rm))l=lm;
else r=rm;
}
printf("%.10f\n",cal((l+r)/2));
}
signed main(){
int T=1;
while(T--)sol();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5968kb
input:
2 1 15 0 10
output:
10.0000000000
result:
ok found '10.0000000', expected '10.0000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 6024kb
input:
3 0.4 100 0.5 100 0.6 100
output:
33.3333333333
result:
ok found '33.3333333', expected '33.3333333', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 6032kb
input:
1 0 1
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5964kb
input:
2 1 0 1 100
output:
-0.0000000000
result:
ok found '-0.0000000', expected '0.0000000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5956kb
input:
1 0.5 100
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5848kb
input:
3 0.4 100 0.6 100 0.6 100
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 5788kb
input:
3 0.2 100 0.2 100 0.8 100
output:
0.0000000000
result:
wrong answer 1st numbers differ - expected: '50.0000000', found: '0.0000000', error = '1.0000000'