UVALive
来源:互联网 发布:网络摄像机组装配件 编辑:程序博客网 时间:2024/06/09 00:26
题目链接:点击打开链接
题目大意:
有n个人为两个候选人(A,B)投票,每人只能投一票,当某人获得的票数多余总票数一半时则获胜,当前已知部分人投票的结果,给定一个概率P,判断A获胜的概率是否大于P。
解题思路:
一:A不能获胜与A一定获胜这两种情况可以直接判断出来。
二:计算当前A的获胜概率P(A),与P作比较。计算A要获胜还至少需要的票数x与当前还剩余可投的票数N,那么当A获得的票数在[X~N]之间时,A均可获胜。所以A获胜的概率为P(A)=(C(N,x)+C(N,x+1)+...+C(N,N))/(2^N),给定的概率为W%,考虑到精度问题,将比较转化为乘法,即比较P(A)*100与(2^N)*W的大小即可。
代码:
#include<iostream>#include<cstring>#include<string>#include<cstdio>#include<algorithm>#define LL long longusing namespace std;LL c[55][55];LL pow_2[55];int main(){ freopen("in.txt","r",stdin); memset(c,0,sizeof c); for(int i=0;i<=50;i++){ c[i][0]=1; for(int j=1;j<=i;j++){ c[i][j]=c[i-1][j-1]+c[i-1][j]; } } pow_2[0]=1; for(int i=1;i<=50;i++)pow_2[i]=pow_2[i-1]*2; int T; cin>>T; int n,x1,x2,w; while(T--){ LL cnt=0; cin>>n>>x1>>x2>>w; if(x1*2>n)cout<<"GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!"<<endl; else if(x2*2>=n)cout<<"RECOUNT!"<<endl; else { int ok=0,i=n/2+1; n-=x1+x2; for(i-=x1;i<=n;i++){ cnt+=c[n][i]; if(cnt*100>w*pow_2[n]){ok=1;break;} } if(ok)cout<<"GET A CRATE OF CHAMPAGNE FROM THE BASEMENT!"<<endl; else cout<<"PATIENCE, EVERYONE!"<<endl; } } return 0;}
然而这个题一直没A,结束后才发现特判条件出了点小问题。
阅读全文
0 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 2017 acmicpc 北京网络赛 IMinimum(线段树求区间最值)
- 【Tensorflow】tf.placeholde函数解释与用法
- 图解HTTPS协议加密解密全过程
- 【牛客】星际穿越
- kubernetes init-container
- UVALive
- POJ
- LeetCode 205. Isomorphic Strings
- 230. Kth Smallest Element in a BST
- Combination Sum
- bzoj 3107: [cqoi2013]二进制a+b 数位dp
- C++实现复数Complex
- 认识HTML5的WebSocket
- Leetcode之Spiral Matrix II 问题