UVA - 557 Burger(汉堡)(dp+概率)
题意:有n个牛肉堡和n个鸡肉堡给2n个孩子吃。每个孩子在吃之前都要抛硬币,正面吃牛肉堡,反面吃鸡肉堡。如果剩下的所有汉堡都一样,则不用抛硬币。求最后两个孩子吃到相同汉堡的概率。
分析:
1、先求最后两个孩子吃到不同汉堡的概率。
2、dp[i]表示2i个人的情况。
3、dp[i + 1] = (2 * i - 1) * dp[i] / (2 * i) 。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b) {
if(fabs(a - b) < eps) return 0;
return a < b ? -1 : 1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 50000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
double dp[MAXN];
void init(){
dp[1] = 1;
for(int i = 1; i < MAXN; ++i){
dp[i + 1] = dp[i] * (2 * i - 1) / (2 * i);
}
}
int main(){
init();
int T;
scanf("%d", &T);
while(T--){
int n;
scanf("%d", &n);
printf("%.4lf\n", 1 - dp[n / 2]);
}
return 0;
}
UVA - 557 Burger(汉堡)(dp+概率)的更多相关文章
- uva 557 Burger
https://vjudge.net/problem/UVA-557 题意: n个人,n/2个牛肉煲,n/2个鸡肉堡 每次抛硬币,根据正反决定每个人吃什么汉堡 如果某一个汉堡被选完了,就不抛了 问最后 ...
- 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 个客人吃,在吃之前抛硬币来决定吃什么,如果剩下的汉堡一样,就不用投了,求最后两个人吃到相同的概率. 析:由于正面考虑还要要不要投硬币,太麻烦,所以我们先 ...
- UVA 557 Burger 排列组合递推
When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party was held at t ...
- Race to 1 UVA - 11762 (记忆dp概率)
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...
- UVa 557 (概率 递推) Burger
题意: 有两种汉堡给2n个孩子吃,每个孩子在吃之前要抛硬币决定吃哪一种汉堡.如果只剩一种汉堡,就不用抛硬币了. 求最后两个孩子吃到同一种汉堡的概率. 分析: 可以从反面思考,求最后两个孩子吃到不同汉堡 ...
- UVA 11427 Expect the Expected(DP+概率)
链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...
- UVa 557 汉堡
https://vjudge.net/problem/UVA-557 题意: 有n个牛肉堡和n个鸡肉堡给2n个孩子吃.每个孩子在吃之前都要抛硬币,正面吃牛肉堡,反面吃鸡肉堡.如果剩下的所有汉堡都一样, ...
- tyvj P1864 [Poetize I]守卫者的挑战(DP+概率)
P1864 [Poetize I]守卫者的挑战 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜 ...
随机推荐
- tomcat点击startup.bat出现闪退,启动不成功的解决办法
问题描述:tomcat点击startup.bat出现命令行闪退的情况 打开startup.bat,在第一行加入 SET JAVA_HOME=D:\jdk\jdk1.8.0_121[jdk路径] SET ...
- CSP-S 2019 复赛游记
自闭游记 >_< Day 0 随便敲了一些板子 当然打了摆. 奶人的话写满了俩黑板啊,没人奶我可海星. 晚上没怎么打摆,随便敲了几道板子,然后很早就回去睡了. Day 1 平静地出发了.. ...
- php 实现店铺装修6
/** * @title 获取预览或发布的蜂店模板样式 * @param store_id 是 string 店铺id * @param type 是 int 装修模板的状态:1-预览蜂店装修模板样式 ...
- [Verilog] indexed part-select +:
That syntax is called an indexed part-select. The first term is the bit offset and the second term ...
- zookeeper加Kafka集群配置
官方 https://zookeeper.apache.org/doc/r3.5.6/zookeeperStarted.html#sc_Prerequisites https://www.cnblog ...
- Jackson自定义反序列化
// 设置jackson时间反系列化格式 SimpleModule module = new SimpleModule(); module.addDeserializer(Date.class, ne ...
- python2学习------基础语法2(函数)
1.函数 # 无参数函数 def loopTest2(): a=1; while a<40: print a; a=a+1; if a==35: continue; else: print 'o ...
- 深入了解memcached
一.memcached如何支持高并发 Memcached使用多路复用 I/O模型(如epoll.select等).传统阻塞 I/O中,系统可能会因为某个用户连接还没做好 I/O准备而一直等待,直到这个 ...
- 7.10 Varnish 优化
- 树莓派1 安装使用 ZeroTier
基于P2P网络的Private LAN工具:ZeroTier Linux (DEB and RPM distributions) We've found a way to make the easy ...