【POJ2598】Match Throwing Game

题面

题解

忘了,只记得是用$sin(x)$的积分搞
还要进行伯努利实验判断输出多少

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<cstdio>
#include<cmath>
#include<algorithm>
#define RG register
using namespace std;

const double PI(acos(-1));
double L, p, sum[1010];
int x, y;

inline double Bernulli(int n, int m, double p, double q) { return log(p) * m + log(q) * (n - m) + sum[n] - sum[n-m] - sum[m]; }
int main()
{
for(RG int i=1;i<1010;i++) sum[i] = sum[i-1] + log(i);
while(~scanf("%lf", &L))
{
if(L < 1) p = 2 * L;
else
{
double k = asin(double(1 / L));
p = 2 * L * (1 - cos(k)) + PI - 2 * k;
}
p /= PI;
y = (x = int(p * 1000)) + 1;
double l = Bernulli(1000, x, p, 1-p), r = Bernulli(1000, y, p, 1-p);
if(l < r) swap(x, y);
printf("%d\n", x);
}
return 0;
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×