QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#595064 | #8037. Gambler's Ruin | Yu_mx | WA | 1ms | 6004kb | C++14 | 1.3kb | 2024-09-28 12:21:53 | 2024-09-28 12:21:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
const int N = 1e6+5;
struct gambler{
double p;
ll c;
bool operator < (gambler &x) const{
return p>x.p||(p==x.p&&c>x.c);
}
}a[N];
ll pre[N];
ll n;
double ans = 0.0;
double calc(int i,int j){
// if(j<=0||j>n) return -1e15;
if(a[i].p+1.0-a[j].p<=1.0) return -1e20;
double x = 1.0/a[i].p;
double sx = 1.0*pre[i];
double y = 1.0/(1.0-a[j].p);
double sy = 1.0*(pre[n]-pre[j-1]);
double t = (sx+sy-1.0*max(sx*x,sy*y));
ans = max(ans,t);
return t;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i].p>>a[i].c;
sort(a+1,a+1+n);
pre[0] = 0;
for(int i=1;i<=n;i++) pre[i] = pre[i-1]+a[i].c;
//double ans = 0.0;
for(int i=1;i<=n-1;i++){
ll l = 1, r = n;
double anst = max(calc(i,l),calc(i,r));
while(l<=r){
int lmid = l+(r-l)/3;
int rmid = r-(r-l)/3;
//cout<<lmid<<' '<<calc(i,lmid)<<endl;
//cout<<rmid<<' '<<calc(i,rmid)<<endl;
if(calc(i,lmid) <= calc(i,rmid)) l = lmid+1;
else r = rmid-1;
}
anst = max(calc(i,l),calc(i,r));
ans = max(ans,anst);
//cout<<anst<<endl;
}
//cout<<calc(1,3)<<endl;
cout<<fixed<<setprecision(10)<<ans<<endl;
}
int main(){
ios;
//ll T;cin>>T;while(T--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5908kb
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: 1ms
memory: 5912kb
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: 1ms
memory: 6004kb
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: 5900kb
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: 5960kb
input:
1 0.5 100
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 5908kb
input:
3 0.4 100 0.6 100 0.6 100
output:
33.3333333333
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '33.3333333', error = '33.3333333'