UVA 557 Burger 排列组合递推
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 排列组合递推的更多相关文章
- UVA 557 - Burger(概率 递推)
Burger When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party was ...
- UVa 557 Burger (概率+递推)
题意:有 n 个牛肉堡和 n 个鸡肉堡给 2n 个客人吃,在吃之前抛硬币来决定吃什么,如果剩下的汉堡一样,就不用投了,求最后两个人吃到相同的概率. 析:由于正面考虑还要要不要投硬币,太麻烦,所以我们先 ...
- 2825 codevs危险的组合(递推)
2825 危险的组合 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 有一些装有铀(用U表示)和铅(用L表示)的盒子,数量均足够 ...
- Crash的游戏 [组合+递推]
题面 思路 问题转化 这个问题的核心在于,我们需要把"加入一个球.拿出一个球"这两个操作转化一下 因为显然两个操作同时进行的话,我们没有办法从单纯的组合意义去分析 我们首先把$m$ ...
- UVA 11077 - Find the Permutations(递推)
UVA 11077 - Find the Permutations option=com_onlinejudge&Itemid=8&page=show_problem&cate ...
- UVA 11077 Find the Permutations 递推置换
Find the Permutations Sorting is one of the most used operations in real ...
- Codeforces Round #526 C - The Fair Nut and String /// 组合递推
题目大意: 给定原字符序列 找出其中所有子序列满足 1.序列内字符都为a 2.若有两个以上的字符 则相邻两个字符在原序列中两者之间存在字符b 的数量 将整个字符序列用b分开 此时再得到每个b之间a的数 ...
- UVA 10559 Blocks(区间DP&&递推)
题目大意:给你玩一个一维版的消灭星星,得分是当前消去的区间的长度的平方,求最大得分. 现在分析一下题目 因为得分是长度的平方,不能直接累加,所以在计算得分时需要考虑前一个状态所消去的长度,仅用dp[l ...
- uva 557 Burger
https://vjudge.net/problem/UVA-557 题意: n个人,n/2个牛肉煲,n/2个鸡肉堡 每次抛硬币,根据正反决定每个人吃什么汉堡 如果某一个汉堡被选完了,就不抛了 问最后 ...
随机推荐
- mac下163企业邮箱客户端的配置
一 添加账户 添加账户->添加其他邮件账户->输入电子邮件地址和密码.(全名随意起). 二 收件服务器和发件服务器的设置 收件服务器:pop.qiye.163. ...
- mvc4 http错误403.14 forbidden
1. 检查服务器上是否安装了“HTTP重定向”功能和“静态内容压缩”功能(在添加/删除程序或增加角色处安装). 2. 应用程序池要被配置为“集成” 3. 把.net 4.0安装在iis上 4. 确保自 ...
- winform 表单正则表达式验证 示例(ValidationRule)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 在EDK里面添加ISE IP core的方法
(1)在ISE下,使用core generator,可以得到xilinx的IP的*.v和*.ngc 文件,将这两个文件拷贝出来: (2)在EDK下使用“Create or Import Periphe ...
- Kinect帮助文档翻译之一 入门
最近在玩Kinect,使用的是Unity,发现网上好像没有什么教程.自己就只有抱着英文版帮助文档啃,真是苦逼 本人英语也不好,大家将就着看吧 Kinect入门帮助 如何运行示例 1 下载并 ...
- 【BZOJ 2324】 [ZJOI2011]营救皮卡丘
Description 皮卡丘被火箭队用邪恶的计谋抢走了!这三个坏家伙还给小智留下了赤果果的挑衅!为了皮卡丘,也为了正义,小智和他的朋友们义不容辞的踏上了营救皮卡丘的道路. 火箭队一共有N个据点,据点 ...
- Android -- 检测耳机插入状态
原理 其实android系统在耳机 ...
- cnblogs体验
用博客园可以让我更好的关注我们班同学的情况,通过关注他们,浏览他们发布的博客,学习到了很 多,比如不同的设计思想,良好的变成习惯,变量命名,缩进,注释等,而且自己不会的,可以帮助自己 有一些想法,是自 ...
- Material
renderer.material 物理材质 实现二维图上的人物动作 新建Material,选择Shader(著色器)为transparent/diffuse(背景透明),将上图拉到背景图选项中. ...
- 向Array中添加堆排序
堆排序思路 堆排序是一种树形选择排序方法(注意下标是从1开始的,也就是R[1...n]). 1) 初始堆: 将原始数组调整成大根堆的方法——筛选算法:比较R[2i].R[2i+1]和R[i],将最大者 ...