UVALive 6672 Bonus Cards
来源:互联网 发布:门诊流程优化 编辑:程序博客网 时间:2024/05/16 06:01
题意:有n个位置,两种竞选方式,一种是icpc,一种是acm,竞选n轮,每次决出一个位置,现在你要竞选,分别求出按icpc方式竞选的概率和按acm方式竞选的概率。icpc占两份,acm占一份。
析:很明显概率dp。若选择icpc方式,dp[i][j]表示到第i轮有j个人按第一种方式竞选成功。若选择acm方式,dp2[i][j]表示到第i轮有j个人竞选成功。
细节参见代码:
#include<iostream>#include<cstdio>#include<cstring>#include<set>#include<map>#include<vector>#include<algorithm>#include<cmath>#include<queue>#include<sstream>#include<cstdlib>using namespace std;const int maxn=3000+5;int n,a,b;double dp[maxn][maxn],dp2[maxn][maxn],ans1,ans2;int ua,ub,la,lb;int main(){ while(~scanf("%d%d%d",&n,&a,&b)) { if(n>a+b) { printf("1.0000000000000000\n"); printf("1.0000000000000000\n"); continue; } ans1=0.0;ans2=0.0; memset(dp,0,sizeof(dp)); memset(dp2,0,sizeof(dp2)); dp[0][0]=1.0; dp2[0][0]=1.0; for(int i=0;i<n;i++) for(int j=0;j<=i&&j<=a;j++) { if(fabs(dp[i][j])<1e-8) continue; ua=j; ub=i-j; la=a-ua; lb=b-ub; double fenmu=1.0/(la*2.0+lb+2.0); ans1+=dp[i][j]*2.0*fenmu; if(la>0) dp[i+1][j+1]+=dp[i][j]*la*2.0*fenmu; if(lb>0) dp[i+1][j]+=dp[i][j]*lb*1.0*fenmu; fenmu=1.0/(la*2.0+lb+1.0); ans2+=dp2[i][j]*fenmu; if(la>0) dp2[i+1][j+1]+=dp2[i][j]*la*2.0*fenmu; if(lb>0) dp2[i+1][j]+=dp2[i][j]*lb*fenmu; } printf("%.12f\n",ans1); printf("%.12f\n",ans2); } return 0;}
0 0
- UVALive 6672 Bonus Cards
- UVALive 4384 Business Cards
- UVALive 5811 Cards
- UVALive 7344 I - Numbered Cards
- UVALive 7278 Game of Cards
- UVALive-7278 - Game of Cards【博弈】【sg定理】
- Cards
- Cards
- Cards
- Cards
- eCryptfs - Bonus
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 记录学习的路程
- java实现之测试第三方接口是否能正确连接
- 生成博客
- 正走向大牛的菜鸟
- 取一个整数a从右端开始的4~7位
- UVALive 6672 Bonus Cards
- 开机出现 system32\config\system,代码:0xc00000e9解决方法
- 浅谈super与this关键字的区别
- 几个 学习网站
- ElasticSearch 常见错误
- WebLogic(12C)——WLST
- 临界区,互斥量,信号量,事件的区别
- 如何重现难以重现的bug
- This version of the rendering library is more recent than your version of ADT plug-in. Please update