hdu 4586 Play the Dice (概率+等比数列)
Play the Dice
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1328 Accepted Submission(s): 429
Special Judge
yuan. What's more, some sids of this dice are colored with a special different color. If you turn this side up, you will get once more chance to roll the dice. When you roll the dice for the second time, you still have the opportunity to win money and rolling
chance. Now you need to calculate the expectations of money that we get after playing the game once.
The first line is an integer n (2<=n<=200), following with n integers ai(0<=ai<200)
The second line is an integer m (0<=m<=n), following with m integers bi(1<=bi<=n), which are the numbers of the special sides to get another more chance.
6 1 2 3 4 5 6
0
4 0 0 0 0
1 3
3.50
0.00
思路:刚開始理解错题意了,老感觉那m个面的数字的大小和结果有关。
事实上,掷到一个特殊面仅仅是得到了一个再次投掷的机会,和第一次投掷的效果全然一样。
sum=a1+a2+...+an; a=sum/n; q=m/n;
ans=a+a*q+a*q^2+...=sum/(n-m);
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define N 205
const int inf=0x3fffffff;
int a[N];
int main()
{
int i,n,m,t;
double sum;
while(scanf("%d",&n)!=-1)
{
sum=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d",&t);
}
if(sum==0)
{
printf("0.00\n");
continue;
}
if(m==n)
{
printf("inf\n");
continue;
}
printf("%.2f\n",sum/(n-m));
}
return 0;
}
hdu 4586 Play the Dice (概率+等比数列)的更多相关文章
- hdu 4586 Play the Dice 概率推导题
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 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 ...
- 概率DP HDU 4586 play the dice
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4586 解题思路: 只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加. ...
- HDU 4586 Play the Dice (数学,概率,等比公式,极限)
题意:给你一个n面的骰子每个面有一个值,然后其中有不同值代表你能获得的钱,然后有m个特殊的面,当你骰到这一面的时候可以获得一个新的机会 问你能得到钱的期望. 析: 骰第一次 sum/n 骰第二 ...
- 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
思路:设期望值为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自动机 ...
- HDU 4586 A - Play the Dice 找规律
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
随机推荐
- centos安装lamp步骤还可以
1. 用yum安装Apache,Mysql,PHP. 1.1安装Apache yum install httpd httpd-devel 安装完成后,用/etc/init.d/httpd start ...
- javascript从作用域链的角度看闭包
闭包 闭包是一个能访问外部函数定义的变量的函数. 为什么? 当访问一个变量时,解释器会首先在当前作用域查找标示符,如果没有找到,就去父作用域找,直到找到该变量的标示符或者不再存在父作用域了,这就是作用 ...
- Python 45 css三种引入方式以及优先级
一:css三种引入方式 三种方式为:行间式 | 内联式 | 外联式 行间式 1.在标签头部的style属性内 2.属性值满足的是css语法 3.属性值用key:value形式赋值,value具 ...
- Python 42 mysql用户管理 、pymysql模块
一:mysql用户管理 什么是mysql用户管理 mysql是一个tcp服务器,应用于操作服务器上的文件数据,接收用户端发送的指令,接收指令时需要考虑到安全问题, ATM购物车中的用户认证和mysql ...
- git add -A (用该命令添加文件时报错)
前言 最近在学着不使用github客户端,而直接用git命令上传代码至github,当使用命令 git add -A 添加所有项目文件时报错 老实说我是蒙蔽的,因为从来没有遇到过这个错,确认输入 ...
- Redis配置文件各项参数说明及性能调优
Redis配置文件参数说明: 1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no 2. 当Redis以守护进程方式运行时,Redis默 ...
- 【PostgreSQL-9.6.3】函数(2)--字符型函数
在上一篇博文中我们交流了数值型函数,这篇我们将讨论PostgreSQL中的字符型函数. 1. reverse(string) reverse函数可以将string字符串的字母显示顺序颠倒. test= ...
- PJAX全局无刷新的设置方法~
先添加必要文件: <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></scrip ...
- POST请求成功,但接口返回数据不正确
事件:使用Jmeter做APP的搜索接口测试,请求成功了,但无论keyword是什么“内容”(这里的内容是带引号的哦),接口返回的内容都是:未匹配到搜索结果 排查问题: keyword=“世界” st ...
- 【airtest, python】报错:requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')),解决方法如下
环境及设备 mac, xcode , iphonex 问题 最近出现一个让人费解的问题,airtest 没跑多长时间,服务就断掉,而且总是报“requests.exceptions.Connectio ...