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. Android Service学习之本地服务

    Service是在一段不定的时间运行在后台,不和用户交互应用组件.每个Service必须在manifest中 通过来声明.可以通过contect.startservice和contect.bindse ...

  2. linux之iptables总结

    netfilter/iptables概述:     netfilter/iptables是Linux内核防火墙架构,由netfilter实现功能,由iptables提供接口.     iptables ...

  3. wpa_supplicant安装

    http://blog.chinaunix.net/uid-28572323-id-3482376.html http://blog.chinaunix.net/uid-26921272-id-341 ...

  4. [ios]ios-Demo4脱衣服/刮奖app-专业

    普通版本完成的锯齿很严重 但是Ios系统中仅CGContextClearRect 并不存在cyclo等方法. 网上查了一些资料. 发现还是利用到了CG 中的Mask来实现效果图: 这种效果可以自定义画 ...

  5. chmod命令用法

    指令名称 : chmod  使用权限 : 所有使用者  使用方式 : chmod [-cfvR] [--help] [--version] mode file...  说明 : Linux/Unix ...

  6. json转换对象

    JSON.parse(jsonstr); //可以将json字符串转换成json对象 JSON.stringify(jsonobj); //可以将json对象转换成json对符串

  7. SQL Server数据库学习笔记-设计表时应该考虑的因素

    设计数据库其实就是设计数据库中的表.到底要注意些什么才能够设计好一个数据库呢?一个宗旨,8个建议. 一个宗旨“尽量少的表,每个表中尽量少的列,合理的表结构”. 8个建议: 第一个,首先要考虑的是咱们这 ...

  8. dev 激活没有权限问题

    用管理员身份打开 Microsoft Visual Studio 2010-->Visual Studio Tools-->Visual Studio 命令提示(2010) 然后输入一下命 ...

  9. EF4.1之基础(实现Code First)

    Code First:顾名思义:就是通过代码生成数据库----通过类生成数据库中对应的表: 首先定义两个类(就是建模的过程): public class Order { public int Orde ...

  10. ionic:Build mobile apps faster with the web technologies you know and love

    http://ionicframework.com/getting-started/ 5 Ionic Framework App Development Tips and Tricks http:// ...