When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party was held at the McDonald's restaurant at South Broadway 202, New York. There were 20 kids at the party, including Ben and Bill. Ronald McDonald had made 10 hamburgers and 10 cheeseburgers and when he served the kids he started with the girl directly sitting left of Bill. Ben was sitting to the right of Bill. Ronald flipped a (fair) coin to decide if the girl should have a hamburger or a cheeseburger, head for hamburger, tail for cheeseburger. He repeated this procedure with all the other 17 kids before serving Ben and Bill last. Though, when coming to Ben he didn't have to flip the coin anymore because there were no cheeseburgers left, only 2 hamburgers.

Ronald McDonald was quite surprised this happened, so he would like to know what the probability is of this kind of events. Calculate the probability that Ben and Bill will get the same type of burger using the procedure described above. Ronald McDonald always grills the same number of hamburgers and cheeseburgers.

The first line of the input-file contains the number of problems n , followed by n times:

a line with an even number [2,4,6,...,100000], which indicates the number of guests present at the party including Ben and Bill.

The output consists of n lines with on each line the probability (4 decimals precise) that Ben and Bill get the same type of burger.

Note: a variance of  is allowed in the output due to rounding differences.

3
6
10
256
0.6250
0.7266
0.9500

 题意: 给你给定2n个人,有n个汉堡和n个 奶酪汉堡,Ben and Bill排在最后,然后抛硬币,正反面分别拿汉堡和奶酪汉堡,如果有一样拿完了就不需要在扔硬币了。求最后ben和bill拿到一样的概率。

题解  

:由于有一样拿完了就不需要在扔硬币了这个条件,我们就反过来推,如果ben和bill拿的不一样,那么硬币肯定要扔到最后,那么也就是说,过程中每个人都要经过人硬币,所以我们求这个概率p,然后1-p即可,公式为C(2n - 2, n -1) * 2 ^ (2n - 2). 但是n有十万,直接求肯定不行,进行递推, p[i+1] / p[i]得到一个式子P[i + 1] = p[i] * (1 - 0.5 / i);

//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; double p[N];
void init() {
p[]=;
for(int i=;i<=N;i++) {
p[i+] = p[i] *(*i-)/(*i);
}
}
int main() {
init();
int T,n;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
printf("%.4f\n",-p[n/]);
}
return ;
}

代码

UVA 557 Burger 排列组合递推的更多相关文章

  1. UVA 557 - Burger(概率 递推)

     Burger  When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party was ...

  2. UVa 557 Burger (概率+递推)

    题意:有 n 个牛肉堡和 n 个鸡肉堡给 2n 个客人吃,在吃之前抛硬币来决定吃什么,如果剩下的汉堡一样,就不用投了,求最后两个人吃到相同的概率. 析:由于正面考虑还要要不要投硬币,太麻烦,所以我们先 ...

  3. 2825 codevs危险的组合(递推)

    2825 危险的组合 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 有一些装有铀(用U表示)和铅(用L表示)的盒子,数量均足够 ...

  4. Crash的游戏 [组合+递推]

    题面 思路 问题转化 这个问题的核心在于,我们需要把"加入一个球.拿出一个球"这两个操作转化一下 因为显然两个操作同时进行的话,我们没有办法从单纯的组合意义去分析 我们首先把$m$ ...

  5. UVA 11077 - Find the Permutations(递推)

    UVA 11077 - Find the Permutations option=com_onlinejudge&Itemid=8&page=show_problem&cate ...

  6. UVA 11077 Find the Permutations 递推置换

                               Find the Permutations Sorting is one of the most used operations in real ...

  7. Codeforces Round #526 C - The Fair Nut and String /// 组合递推

    题目大意: 给定原字符序列 找出其中所有子序列满足 1.序列内字符都为a 2.若有两个以上的字符 则相邻两个字符在原序列中两者之间存在字符b 的数量 将整个字符序列用b分开 此时再得到每个b之间a的数 ...

  8. UVA 10559 Blocks(区间DP&&递推)

    题目大意:给你玩一个一维版的消灭星星,得分是当前消去的区间的长度的平方,求最大得分. 现在分析一下题目 因为得分是长度的平方,不能直接累加,所以在计算得分时需要考虑前一个状态所消去的长度,仅用dp[l ...

  9. uva 557 Burger

    https://vjudge.net/problem/UVA-557 题意: n个人,n/2个牛肉煲,n/2个鸡肉堡 每次抛硬币,根据正反决定每个人吃什么汉堡 如果某一个汉堡被选完了,就不抛了 问最后 ...

随机推荐

  1. ASP.NET Web API 2 对 CORS 的支持

    CORS概念 跨域资源共享 (CORS) 是一种万维网联合会 (W3C) 规范(通常被认为是 HTML5 的一部分),它可让 JavaScript 克服由浏览器施加的同域策略安全限制. 所谓同域策略, ...

  2. java 静态变量生命周期(类生命周期)

    Static: 加载:java虚拟机在加载类的过程中为静态变量分配内存. 类变量:static变量在内存中只有一个,存放在方法区,属于类变量,被所有实例所共享 销毁:类被卸载时,静态变量被销毁,并释放 ...

  3. FastDFS安装配置

    FastDFS FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传.下载等服务 ...

  4. 怎样把php数组转换成字符串,php implode()

    实例代码 一维数组转换成字符串代码! <?php $arr1=array("shu","zhu","1"); $c=implode(& ...

  5. Sprint会议-初步组织划分

    主题:Spring冲刺计划会议,组员已认领方式领取任务,对个人任务进行详细划分. 日期:2015.4.26 地点:学一食堂二楼 与会人员:王雪青.陆宇.徐擎天.张文冬.赵建松 索引表 因早期任务的认领 ...

  6. 任务:写一个tomcat自启动脚本

    写一篇<gitlab无法启动了应该怎么办>

  7. javascript学习小记(一)

    大四了,课少了许多,突然之间就不知道学什么啦.整天在宿舍混着日子,很想学习就是感觉没有一点头绪,昨天看了电影激战.这种纠结的情绪让我都有点喘不上气啦!一点要找点事情干了,所以决定找个东西开始学习.那就 ...

  8. android 通过工具抓包

    工具: 1.tcpdump :http://www.strazzere.com/android/tcpdump 2.wireshark:http://pan.baidu.com/s/1geooiav ...

  9. Ngrok 内网穿透神器(转载)

    mac上配置web服务: http://note.rpsh.net/posts/2013/11/27/osx-10-9-apache-server-php-mysql/ Ngrok 内网穿透神器 由于 ...

  10. hdu 4685 二分匹配+强连通分量

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4685 题解: 这一题是poj 1904的加强版,poj 1904王子和公主的人数是一样多的,并且给出 ...