QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#447900 | #8785. Fake Coin and Lying Scales | lichenghan | WA | 7ms | 4096kb | C++14 | 1.2kb | 2024-06-18 23:54:25 | 2024-06-18 23:54:27 |
Judging History
answer
#include <bits/stdc++.h>
#define dbg(...) (fprintf(stderr,##__VA_ARGS__),fflush(stderr))
#define dputs(str) dbg(str "\n")
using namespace std;
double add_ln(double x,double y){
if(x>y) swap(x,y);
if(x-y>=30) return x;
return y+log(exp(x-y)+1);
}
double fact(int x){
return (x+0.5)*log(x);
}
double binom(int u,int d){
if(d==0||d==u) return 0;
return fact(u)-fact(d)-fact(u-d)-1;
}
long long n,k;
void solve(){
scanf("%lld%lld",&n,&k);
if(k==0){
printf("%.20lf\n",n*log(3));
return;
}
double bot=log(3*k+1);
if(k>=n) return (void) printf("%.20lf\n",bot);
double ans=log(3)*n+bot;
double div=0;
if(2*k>=n){
div=1;
}else{
for(int i=0;i<=40&&i<=k;i++){
div=add_ln(div,binom(n,k-i)+log(2)*(k-i));
}
}
ans-=div;
// printf("%.20lf %.20lf\n",bot,ans);
printf("%.20lf\n",max(bot,ans));
}
void test(){
auto exact_binom=[&](int n,int k){
double ans=0;
for(int i=n;i>=n-k+1;i--) ans+=log(i);
for(int i=k;i>=1;i--) ans-=log(i);
return ans;
};
// const int n=40,k=20;
const int n=1e6,k=5e5;
printf("%+.4lf\n",exact_binom(n,k)-binom(n,k));
}
int main(){
// test(); return 0;
int tc;
scanf("%d",&tc);
while(tc--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4096kb
input:
2 100 0 100 1
output:
109.86122886681097554629 105.93924719644667220564
result:
ok q=0 (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 4096kb
input:
10000 32 6 45 98 67 57 35 70 29 3 22 81 59 12 48 16 63 69 99 36 60 36 32 47 73 91 81 30 7 7 71 57 38 60 35 19 92 40 3 17 21 71 54 62 95 67 60 50 10 20 19 80 64 73 10 21 70 97 84 3 26 22 38 47 37 38 31 91 11 37 73 17 75 98 8 74 73 60 87 10 94 48 35 73 18 14 88 25 61 54 39 59 100 90 70 98 73 21 92 11 ...
output:
20.17550472840905939620 5.68697535633982020897 77.75451781757681146701 5.35185813347606664792 23.87554244816926285466 5.49716822529320214841 32.30953256311723009730 16.89647190708933521819 5.33753807970131788352 25.84965944883099098206 69.60808520231572060766 4.95582705760126085437 5.613128106388070...
result:
wrong answer WA (test case 3)