# RMRC2016问题 B: Election（概率计算）

[提交][状态][讨论版]

## 题目描述

After all the fundraising, campaigning and debating, the election day has finally arrived. Only two candidates remain on the ballot and you work as an aide to one of them.
Reports from the voting stations are starting to trickle in and you hope that you can soon declare a victory.
There are N voters and everyone votes for one of the two candidates (there are no spoiled ballots). In order to win, a candidate needs more than half of the votes. A certain number M≤N of ballots have been counted, and there are Vi votes for candidate i (V1+V2 = M), where V1 is the number of votes your candidate received.
Due to the historical data and results of highly scientific polls, you know that each of the remaining votes has a 50% chance to go to your candidate. That makes you think that you could announce the win before all the votes are counted. So, if the probability of winning strictly exceeds a certain threshold W, the victory is yours! We just hope you are sure of this, we don’t want any scandals...

## 输入

The first line of input contains a single positive integer T≤100 indicating the number of test cases. Next
T lines each contain four integers: N, V1, V2 and W as described above.
The input limits are as follows:
1≤N≤50
50≤W<100
V1,V2≥0
V1 + V2≤N

## 输出

For each test case print a single line containing the appropriate action:
If the probability that your candidate will win is strictly greater than W%, print
GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!
If your candidate has no chance of winning, print
RECOUNT!
Otherwise, print
PATIENCE, EVERYONE!

## 样例输入

4
5 0 3 75
5 0 2 75
6 1 0 50
7 4 0 75


## 样例输出

RECOUNT!
PATIENCE, EVERYONE!
PATIENCE, EVERYONE!
GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!

【解析】：

p=C(m,3)*0.5^5 + C(m,4)*0.5^5 + C(m,5)*0.5^5

【代码】：

#include <stdio.h>
#include <math.h>
typedef long long ll;
ll qpow(ll n,ll m){ll ans=1;while(m){if(m%2)
ans=(ans*n);m/=2;n=(n*n);}return ans;}

ll Cf[55][55];
int main()
{
//组合数打表
Cf[0][0]=1;//特殊
for(int i=1;i<=51;i++)
for(int j=0;j<=51;j++)
Cf[i][j]=(j==0)?1:(Cf[i-1][j]+Cf[i-1][j-1]);
int n,v1,v2,w,T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&n,&v1,&v2,&w);
int m=n-v1-v2;//剩余人数
int sh=n/2+1;//获胜最少票数
int t=sh-v1;//还差几票
ll p=0;
int flag=0;
for(int i=t>0?t:0;i<=m;i++)
{
p+=Cf[m][i];
//printf("%lf\n",p/pow(2,m));
if(p*100>w*qpow(2,m))
{
flag=1;break;
}
}
if(flag)
puts("GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!");
else if(2*v2>=n)
puts("RECOUNT!");
else
puts("PATIENCE, EVERYONE!");
}
return 0;
}

#### CERC2017 F: Faulty Factorial 简单数论题

2018-04-08 16:14:38

#### RMRC2017 Polyline Simplification

2018-04-26 13:43:36

#### 【树形dp入门】没有上司的舞会 @洛谷P1352

2018-05-08 21:39:27

#### 换了你， 你会杀了谁

2007-05-25 18:55:00

#### RMRC2016 G:Flow Shop (DP)

2017-09-04 21:30:52

#### 01背包 第k优解

2017-11-27 19:05:56

#### hdu 5950 数学公式 + 矩阵快速幂

2017-10-15 14:16:07

#### codeforces 4D D. Mysterious Present (dp||LIS)

2018-05-08 20:11:02

#### poj 3311 Hie with the Pie（floyd+状态压缩）

2017-11-06 21:09:34

#### 【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D

2018-05-02 12:54:06