愤怒的巨巨
链接:https://ac.nowcoder.com/acm/problem/16138
来源:牛客网
**题目描述 **
在511没人敢惹盼成巨巨,因为盼成巨巨是我们511的学神!
周末,巨巨让乙超大佬去买一根香蕉,可你是知道的,买来的香蕉很可能是坏的,经过乙超大佬的长期调研,源源家香蕉中次品率为p,因为乙超超BYQ(too you qian),如果买到坏香蕉,他会认栽,但他害怕巨巨愤怒,他会继续买下去,直到买到好香蕉为止!
他想知道他必须买香蕉的个数的期望值,如果注定他买不到好香蕉请输出 ”Sorrry,JuJu!”
输入描述:
输入实数p (0≤p≤1且保证p的小数位不超过6位)
输出描述:
输出一行:
如果买不到好香蕉,输出”Sorrry,JuJu!”(忽略双引号)
否则输出期望值的最简分数形式:c/d.
示例1
输入
复制
0.5
输出
复制
2/1
示例2
输入
复制
1.00
输出
复制
Sorrry,JuJu!
题意
中文题
题解
水题,但是太久没见几何概型了,写一下。
几何概型
E
(
x
)
=
1
p
E(x)=\cfrac{1}{p}
E(x)=p1
另外这题,精度相当坑
两个选择,
1
e
6
−
p
∗
1
e
6
1e6-p*1e6
1e6−p∗1e6或者
(
1
−
p
)
∗
1
e
6
+
0.5
(1-p)*1e6+0.5
(1−p)∗1e6+0.5
虽然咱也不知道为啥加0.5的能过,我寻思着
1
1
1减一个六位小数还能产生七位小数不成
拍了十万组数据,没找到任何一个6位小数有问题的。强烈怀疑数据不止六位小数。
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <assert.h>
#include <cmath>
#include <ctime>
using namespace std;
#define me(x,y) memset((x),(y),sizeof (x))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define SGN(x) ((x)>0?1:((x)<0?-1:0))
#define ABS(x) ((x)>0?(x):-(x))
// #define int __int128
typedef long long ull;
typedef unsigned long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll maxn = 2010;
const double INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-17;
const double PI = std::acos(-1);
int main(){
// ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("1in.in","r",stdin);
freopen("1out.out","w",stdout);
#endif
double p;
cin>>p;
if(p == 1.0) puts("Sorrry,JuJu!");
else{
int k = 1e6;
int pp = k-p*k;
if(pp == k) puts("1/1");
else{
int gd = __gcd(k,pp);
k /= gd;
pp /= gd;
printf("%d/%d",k,pp);
}
}
return 0;
}