Election
来源:互联网 发布:linux文件夹同步工具 编辑:程序博客网 时间:2024/05/20 07:54
F(1967): Election
Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 495 Solved: 44Description
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...
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, 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
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
45 0 3 755 0 2 756 1 0 507 4 0 75
Sample Output
RECOUNT!PATIENCE, EVERYONE!PATIENCE, EVERYONE!GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!
题意:如果您的候选人获胜的概率严格大于W%,输出 GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!
如果您的候选人没有获胜的机会,输出 RECOUNT!
否则,输出 PATIENCE, EVERYONE!
直接贴代码:/*F题:高中的排列组合知识就可以解决,从n个物品中选择m个物品,每个物品被选择的概率都是0.5;C(m,n)*(0.5)^m(选中)*(0.5)^(n-m)(未选中)=C(m,n)*(0.5)^n;根据这个公式,再判断v1得到几票可以赢。*/#include<cstdio>#include<cmath>using namespace std;typedef long long ll;ll C(int n, int m){ll ans = 1;ll ans2 = 1;int i, j;for (i = n, j = m; i>n - m; i--, j--){ans *= i;if (ans%j == 0)ans /= j;elseans2 *= j;}return ans / ans2;}int main(){int n, v1, v2, t;double w;scanf("%d", &t);while (t--){scanf("%d%d%d%lf", &n, &v1, &v2, &w);double sum = 0;w /= 100.0;for (int i = n / 2 + 1 - v1; i <= n - v1 - v2; i++){sum += 1.0*C(n - v1 - v2, i)*pow(0.5, n - v1 - v2);//重点知识 }if (v2 == n / 2 && n % 2 == 0)printf("RECOUNT!\n");//特判 else{if (v1 >= (n / 2 + 1) || sum>w)printf("GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!\n");else if (v2 >= (n / 2 + 1))printf("RECOUNT!\n");elseprintf("PATIENCE, EVERYONE!\n");}}return 0;}
- Election
- Election
- Election Time
- 1967: Election
- Election Time
- Election方法1
- Election方法2
- fjnu 1571 Election
- pku3664 Election Time
- 补缺选举 by-election
- zoj 1854 Election
- poj 2643 Election
- poj 3664 Election Time
- POJ2643 Election(MAP)
- POJ 3905 Perfect Election
- zoj1854-Election(wa)
- BNUOJ 14362 Election Time
- ZOJ 1854 Election
- C语言控制台应用程序GDI绘制正弦曲线
- J
- C++ 重新定义继承而来的非虚函数
- 不可变数组的基本操作
- Java枚举类型
- Election
- wind(万得)资讯金融终端登录失败问题
- 每日一题——子树
- webview--连接百度
- 排列 permutation 算法竞赛入门经典第二版 习题2-6
- jdbc+sql+preparedStatement使用预编译实现增添数据
- java单元测试之如何实现异步接口的测试案例
- ARouter源码解析05-自动参数注入
- 对于订餐系统的一些扩展的感受