csu:1967-Election(组合数学)

Description

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 V1is 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...

Input

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, V1V2 and W as described above.

The input limits are as follows:

1 ≤ N ≤ 50
50 ≤ W < 100
V1V2 ≥ 0
V1 + V2 ≤ N

Output

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!

Sample Input

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

Sample Output

RECOUNT!
PATIENCE, EVERYONE!
PATIENCE, EVERYONE!

GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!

思路:

数学已经退化到小学生地步了吧,这道题卡了两个小时。。。首先思路还是很简单的我们枚举有几个人投a,有几个人投b,记录awinb的情况数,然后处于总情况数就行了

,但是这里需要注意的是这里由于每一个人都是不同的个体,所以枚举有几人投a,几个人投b的情况是,每种情况不能是简单的记为1,而是组合数c(n,i)

(这里一开始没想到,数学已渣成shit)接下来的问题就是怎么记录组合数,根据如果我们直接去算的话,

复杂度肯定是会炸的,其实计算组合数有这样的一个公式,才c(n,m) = c(n-1,m-1)+c(n-1,m),这样的话我们根据这个递推式去算就行了,复杂度就是m*n的

当n==m时不满足上术公式,所以写全部初始化为一。

ac代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<sstream>
#include<queue>
#include<set>
#include<cmath>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int T;
int n;;
int v1,v2,w;
LL mp[51][51];
LL thepow(int x)
{
    LL res = 1;
    for(int i = 1;i<=x;i++)
        res*=2LL;
    return res;
}
int main()
{
    scanf("%d",&T);
    for(int i = 0;i<=50;i++)
    {
        for(int j = 0;j<=50;j++)
            mp[i][j] = 1;
    }
    for(int i = 1;i<=50;i++)
    {
        for(int j = 1;j<i;j++){
            mp[i][j] = mp[i-1][j]+mp[i-1][j-1];
        }
    }
    //mp[0][0] = 1;
    while(T--)
    {
        scanf("%d%d%d%d",&n,&v1,&v2,&w);
        LL tmp = n-v1-v2;
        LL win1 = 0;
        for(int i=0;i<=tmp;i++){
            int tmp1 = v1+i;
            int tmp2 = v2+tmp-i;
          //  cout<<tmp1<<' '<<tmp2<<endl;
            if(tmp1>tmp2){
                win1+=mp[tmp][i];
                //cout<<tmp<<' '<<i<<' '<<mp[tmp][i]<<endl;
                }
        }
       // cout<<pow(2,tmp)<<' '<<win1<<endl;
            if((win1*100>(thepow(tmp)*w)))
                puts("GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!");
            else if(win1)
            {
                puts("PATIENCE, EVERYONE!");
            }
            else
                puts("RECOUNT!");
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值