HDU 4586 Play the Dice (数学,概率,等比公式,极限)
题意:给你一个n面的骰子每个面有一个值,然后其中有不同值代表你能获得的钱,然后有m个特殊的面,当你骰到这一面的时候可以获得一个新的机会
问你能得到钱的期望。
析:
骰第一次 sum/n
骰第二次 sum/n*(m/n)
骰第三次 sum/n*(m/n)*(m/n)
骰第四次 sum/n*(m/n)*(m/n)*(m/n)
............
骰第k次
sum/n*(m/n)^k
即 sum/n*(1+q+q^2+q^3+……+q^k) q=m/n k=inf
所以 sum/n*(1/(1-m/n)) = (sum/n)*(n/n-m) =sum/(n-m)
那么 n=m时候期望无限大
notice sum等于0的时候直接输出 0.00
代码如下:
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 200 + 5;
const long double eps = 1e-1000;
int a[maxn]; int main(){
int n, m;
while(scanf("%d", &n) == 1){
int sum = 0;
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
sum += a[i];
} scanf("%d", &m);
int x;
for(int i = 0; i < m; ++i)
scanf("%d", &x); if(!sum){
printf("%.2lf\n", 0.0);
continue;
}
else if(sum && m == n){
printf("inf\n");
continue;
} printf("%.2lf\n", sum*1.0/(n-m)); }
return 0;
}
HDU 4586 Play the Dice (数学,概率,等比公式,极限)的更多相关文章
- hdu 4586 Play the Dice(概率dp)
Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equ ...
- hdu 4586 Play the Dice (概率+等比数列)
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...
- 概率DP HDU 4586 play the dice
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4586 解题思路: 只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加. ...
- HDU 4586 Play the Dice(数学期望)
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 4586 Play the Dice 概率推导题
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- hdu - 3959 Board Game Dice(数学)
这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...
- hdu 4586 Play the Dice
思路:设期望值为s,前m个是再来一次机会,则有 s=(a[1]+s)/n+(a[2]+s)/n+……+(a[m]+s)/n+a[m+1]/n…… 化简:(n-m)s=sum 当sum=0时,为0: 当 ...
- HDU 5955 Guessing the Dice Roll
HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...
- hdu 5955 Guessing the Dice Roll 【AC自动机+高斯消元】
hdu 5955 Guessing the Dice Roll [AC自动机+高斯消元] 题意:给出 n≤10 个长为 L≤10 的串,每次丢一个骰子,先出现的串赢,问获胜概率. 题解:裸的AC自动机 ...
随机推荐
- 关于最大传输单元(MTU)的整理
MTU设置不当,可能会导致许多网络问题,如某些网络应用无法使用,某些网站无法访问等.下面是在网上搜索整理的关于MTU设置的东西,某些可能未作验证,仅供参考. 1. 如何确定网络MTU 某些ISP接入的 ...
- zabbix agent主动模式与proxy模式,实现公网zabbix监控私网客户机
zabbix agent主动模式,实现公网zabbix监控私网客户机 zabbix_server端当主机数量过多的时候,由Server端去收集数据,Zabbix会出现严重的性能问题,主要表现如下: ...
- 搭建Lepus数据库监控系统-记录
一. 安装环境 系统环境:centos6.5 IP:192.168.30.242 hostname:vpn.org 软件:LAMP均已安装.(请确保这些正常安装,并能使用). 系统核心包:(摘自官方 ...
- 用户从手机的浏览器访问www.baidu.com,看到的可能跟桌面PC电脑,是不太一样的网页效果,会更适合移动设备使用。请简要分析一下,实现这种网页区分显示的原因及技术原理。
手机的网速问题.屏幕大小.内存.CPU等.通过不同设备的特征,实现不同的网页展现或输出效果.根据useragent.屏幕大小信息.IP.网速.css media Query等原理,实现前端或后端的特征 ...
- Django的视图层
HttpResquest对象: request属性: /* 1.HttpRequest.GET 一个类似于字典的对象,包含 HTTP GET 的所有参数.详情请参考 QueryDict 对象. 2.H ...
- 【转】Android开发笔记——圆角和边框们
原文地址:http://blog.xianqu.org/2012/04/android-borders-and-radius-corners/ Android开发笔记——圆角和边框们 在做Androi ...
- 【图片】机器学习--名画风格 neural-style
neural-style 学习画作风格,将风格施加到另外一张图片中 例如将名画<星夜>的风格施加到一副建筑照片中: 源码 https://github.com/jcjohnson/neur ...
- Netty面试题
1.BIO.NIO和AIO的区别? BIO:一个连接一个线程,客户端有连接请求时服务器端就需要启动一个线程进行处理.线程开销大. 伪异步IO:将请求连接放入线程池,一对多,但线程还是很宝贵的资源. N ...
- leetcode703
class KthLargest { public: KthLargest(int k, vector<int> nums) { size = k; for(auto num:nums){ ...
- Maven中dependencyManagement使用
在Maven中dependencyManagement的作用其实相当于一个对所依赖jar包进行版本管理的管理器. 在dependencyManagement下申明的dependencies,Maven ...