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自动机 ...
随机推荐
- 高效网页去重算法-SimHash
记得以前有人问过我,网页去重算法有哪些,我不假思索的说出了余弦向量相似度匹配,但如果是数十亿级别的网页去重呢?这下糟糕了,因为每两个网页都需要计算一次向量内积,查重效率太低了!我当时就想:论查找效率肯 ...
- node中一个基本的HTTP客户端向本地的HTTP服务器发送数据
上一篇讲到了node可以轻松的向其他请求数据. 这一篇就来讲讲向本地服务器的数据交互. HTTP服务器代码,s.js var http=require("http"); var s ...
- Servlet的复习
Servlet概述 在JavaWeb阶段,使用Servlet是很经常的是事情,Servlet作为MVC中控制器(C)的存在,是不可缺少的一部分.当然Servlet作为JavaWeb的三大组件之一(其他 ...
- 显示本月日历demo
import java.text.DateFormatSymbols; import java.util.Calendar; import java.util.GregorianCalendar; p ...
- CC1,IceBreak,Hello world ,hello toastmaster
this is my first speech:icebreak in toastmaster,it is precious memory for me,this is first time that ...
- Python+Selenium爬虫实战一《将QQ今日话题发布到个人博客》
前提条件: 1.使用Wamp Server部署WordPress个人博客,网上资料较多,这里不过多介绍 思路: 1.首先qq.com首页获取到今日话题的的链接: 2.通过今日话题链接访问到今日话题,并 ...
- Defining Python Source Code Encodings
Defining the Encoding Python will default to ASCII as standard encoding if no other encoding hints a ...
- HTTP代理访问
http请求 http://192.168.19.106:8090/pim/mcloud/device/exist.action 代理ip及端口 120.197.233.205 80 wire ...
- jQuery自动触发事件
转自:https://blog.csdn.net/CY_LH/article/details/78982218 常用模拟 有时候,需要通过模拟用户操作,来达到单击的效果.例如在用户进入页面后,就触发c ...
- 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 9_Neural Networks learning
神经网络的学习(Neural Networks: Learning) 9.1 代价函数 Cost Function 参考视频: 9 - 1 - Cost Function (7 min).mkv 假设 ...