习题10-12 UVA - 557 Burger 汉堡
  gSHLoS4ND9Hs 2023年11月02日 47 0


大体题意:

告诉你有n个学生,有n/2个牛肉堡,和n/2个鸡肉堡,求最后两个孩子吃相同汉堡的概率!

思路:

请教的队友~~

先算不同的概率!

从剩下的n-2个人中,选择(n-2)/2个人 吃鸡肉,剩下(n-2)/2 吃牛肉堡!

这样概率就是C(n-2,(n-2)/2)*(1/2)^(n-2)

算算递推式 就可算出 ans[n]  = ans[n-2] * (n-3)*1.0/(n-2);


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;
double ans[maxn];
void init(){
	ans[2] = 1.0;
	for (int n = 4; n < maxn; n += 2)
		ans[n] = ans[n-2] * (n-3)*1.0/(n-2);
}
int main(){
	int T,n;
	init();
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		printf("%.4lf\n",1.0-ans[n]);
	}
	return 0;
}




【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  Fwc2AKebEVGe   2023年11月02日   37   0   0 #define#includei++
  wD98WYW8hiWJ   2023年11月20日   21   0   0 #include
  EhkezVjvcUv6   2023年11月02日   40   0   0 #includei++测试数据
  v0MZS93bOvwU   2023年11月02日   36   0   0 #include
  PVcilKyJJTzb   2023年11月02日   58   0   0 unix硬件平台c语言
  Mqh2iumZ9USt   2023年11月02日   30   0   0 #includei++ios
gSHLoS4ND9Hs