2015 ACM/ICPC North America Qualifier B. Bobby's Bet(二项式概率)

数据很小,二项式计算cdf * w 是否大于1就行

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
#define limit (200000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO  ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a  ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\akioi\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\akioi\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
inline ll read(){
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    ll sign = 1, x = 0;char s = getchar();
    while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
    while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
    return x * sign;
#undef getchar
}//快读
void print(ll x) {
    if(x/ 10) print(x / 10);
    *O++=x % 10+'0';
}
void write(ll x) {
    if(x < 0)putchar('-'),x = -x;
    print(x);
    fwrite(obuf,O-obuf,1,stdout);
    O = obuf;
}
const int mod = 1000000007;
ll quickPow(ll base, ll expo){
    ll ans = 1;
    while (expo){
        if(expo & 1)(ans *= base) %= mod;
        expo >>= 1;
        base = base * base;
        base %= mod;
    }
    return ans % mod;
}
ll C(ll n, ll m){
    if(n < m)return 0;
    ll x = 1, y = 1;
    if(m > n - m)m = n - m;
    rep(i ,0 , m - 1){
        x = x * (n - i) % mod;
        y = y *  (i + 1) % mod;
    }
    return x * quickPow(y, mod - 2) % mod;
}
ll lucas(ll n, ll m){
    return !m || n == m ? 1 : C(n % mod, m % mod) * lucas(n / mod, m / mod) % mod;
}
int n,k;
int kase;
int a[limit];
void solve(){
    int r,s,x,y,w;
    cin>>r>>s>>x>>y>>w;
    double p = 1.0 / s * (s - r + 1);
    double ans = 0;
    rep(i,x,y){
        ans += C(y,i) * pow(p,i) * pow(1-p,y - i);
    }
    if(ans * w > 1.0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;

}
int main() {
#ifdef LOCAL
    FOPEN;
    //FOUT;
#endif
    FASTIO
    cin>>kase;
    while (kase--)
        solve();
    cerr << "Time elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << "s\n";
    return 0;
}

 

posted @ 2021-02-01 13:21  tiany7  阅读(76)  评论(0编辑  收藏  举报