-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathchefyoda.cpp
More file actions
72 lines (63 loc) · 1.34 KB
/
chefyoda.cpp
File metadata and controls
72 lines (63 loc) · 1.34 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<bits/stdc++.h>
#define MAX 1000000
#define DEBUG(x) do { std::cout << #x << ": " << x << " "; } while (0)
using namespace std;
double coeff(int n,int k){
double c[MAX]={0};
int j;
double x=1; //sum of binomial coefficients less than k
c[0]=1;
if(k<=n/2)
{
for(int i=1;i<k;++i) // nCk= 1..k|^| (n+1-i)/i
{
c[i]=(c[i-1]/i)*(n+1-i);
x+=c[i];
//DEBUG(x);
}
}
else{ //subtract last binomial coefficients from 2^n
x= pow(2,n)-c[0];
k=n-k+1;
for(int i=1;i<k;++i) // nCk= 1..k|^| (n+1-i)/i
{
c[i]=(c[i-1]/i)*(n+1-i);
x-=c[i];
//DEBUG(x);
}
}
//cout<<endl;
return x;
}
int main()
{
int a,b;
float k,n;
int t;
double ans,x=0;
cin>>t;
while(t--){
cin>>a>>b>>k>>n;
ans=0;
if(k==0)//no need to win
{
ans=1;
}
else if(a%2==0 && b%2==0) //chef wins
{
ans=1;
}
else if(a%2!=0 && b%2!=0) //yoda wins
{
ans=0;
}
else
{
ans= coeff(n,k); //P(X<k)
ans=ans/pow(2,n);
ans=1-ans; //P(X>=k)
}
printf("%.6f\n",ans);
}
return 0;
}