TOJ 3488 Game Dice
描述
In the game of Dungeons & Dragons, players often roll multi-sided dice to generate random numbers which determine the outcome of actions in the game. These dice come in various flavors and shapes, ranging from a 4-sided tetrahedron to a 20-sided isocahedron. The faces of an n-sided die, called dn for short, are numbered from 1 to n. Ideally, it is made in such a way that the probabilities that any of its n faces shows up are equal. The dice used in the game are d4, d6, d8, d10, d12, and d20.
When
generating random numbers to fit certain ranges, it is sometimes
necessary or desirable to roll several dice in conjunction and sum the
values on their faces. However, we may notice that although different
combinations of dice yield numbers in the same range, the probabilities
of rolling each of the numbers within the range differ entirely. For
example, a d6 and a d10 afford a range of 2 to 16 inclusive, as does two
d8s, but the probability of rolling a 9 differs in each circumstance.
Your task in this problem is to determine the probability of rolling a certain number, given the set of dice used.
输入
The
input test file will contain multiple cases, with each case on a single
line of input. The line begins with an integer d (where 1 ≤ d ≤ 13),
the number of dice rolled. Following are d descriptors of dice, which
can be any of “d4”, “d6”, “d8”, “d10”, “d12”, or “d20”. The last number
on each line is an integer x (where 0 ≤ x ≤ 1000), the number for which
you are to determine the probability of rolling with the given set of
dice. End-of-input is marked by a single line containing 0; do not
process this line.
输出
For
each test case, output on a single line the probability of rolling x
with the dice, accurate to five decimal places. Note that even if there
trailing zeros, you must show them (see Test problem for an example of
decimal formatting).
样例输入
1 d10 5
2 d6 d6 1
2 d10 d6 9
2 d8 d8 9
0
样例输出
0.10000
0.00000
0.10000
0.12500 题意:求几个筛子相加==x的概率,母函数问题。
#include <stdio.h>
#include <string.h>
#define MAXN 13001 __int64 a[MAXN],b[MAXN];
int d[];
int main(int argc, char *argv[])
{
__int64 n,k,all;
while(scanf("%I64d",&n)!=EOF && n){
all=;
for(int i=; i<=n; i++){
scanf("%d%d",&d[i]);
all*=d[i];
}
scanf("%I64d",&k);
a[]=;
__int64 sum=,sum1;
for(int i=; i<=n; i++){
sum1=sum+d[i];
memset(b,,sizeof(__int64)*(sum1+));
for(int j=; j<=sum; j++){
for(int k=;k<=d[i]; k++){
b[j+k]=b[j+k]+a[j];
}
}
memcpy(a,b,sizeof(__int64)*(sum1+));
sum=sum1;
}
printf("%.5lf\n",double(a[k])/all);
}
return ;
}
TOJ 3488 Game Dice的更多相关文章
- HDOJ 4652 Dice
期望DP +数学推导 Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- 三种renderman规范引擎的dice对比
次表面做的有些烦躁,既然如此,索性先记一下前一阵比较的PIXIE.3delight.prman的dice方式. 研究过reyes的人都知道dice,简而言之,就是为了生成高质量高精度的图片(电影CG) ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- hdu 4586 Play the Dice 概率推导题
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 概率 Gym 100502D Dice Game
题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...
- HDU 5955 Guessing the Dice Roll
HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...
- UVALive 7275 Dice Cup (水题)
Dice Cup 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/D Description In many table-top ...
- HDU 4586 A - Play the Dice 找规律
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
随机推荐
- Sharepoint2013搜索学习笔记之自定义查询规则(十)
自定义查询规则,可以根据搜索的关键字将指定的一个或一堆搜索结果提升到第一的位置,如我搜索周杰伦,可以指定搜索最靠前的结果是sharepoint网站内周杰伦的视频如下图: 第一步,进入管理中心,点击管理 ...
- 排序算法汇总(java实现,附源代码)
整理系统的时候发现了原来写的各种算法的总结,看了一下,大吃一惊,那时候的我还如此用心,具体的算法,有的已经模糊甚至忘记了,看的时候就把内容整理出来,顺便在熟悉一下,以后需要的时候就可以直接过来摘抄了. ...
- Ubuntu下添加Python环境变量
最近把自己在windows上的Django项目放在的Ubuntu上,启动时提示找不到模块 原来是自己的项目用的是虚拟环境,安装的第三方库全部在虚拟环境中 AutoTestSite/venv/Lib/s ...
- .Net Core .Net Core的学习
.Net Core 学习 一.什么是.net core? 百度百科: https://baike.baidu.com/item/.net%20core/20130686?fr=aladdin 个人总结 ...
- vs2015 使用 Eazfuscator.NET 3.3
出现问题: Unable to cast object System.Xml.XmlComment’ to type ‘System.Xml.XmlElement’ 解决办法: 打开 *.csproj ...
- linux 改变系统时间
date 查看系统时间 date -s 04/05/16 日期设置成2016年4月5日 date -s 15:03:32 日期设置成2016年4月5日15:03:32 上述两步可以直接写成这样一 ...
- 条目六《当心C++编译器中最烦人的分析机制》
当心C++编译器中最烦人的分析机制 C++是较为底层的面相对象语言,在底层的语法规则分析中,有很多隐藏的分析机制. C++中的普遍规律相符,即尽可能地解释为函数声明. 把形式参数的声明用括号括起来是非 ...
- Axure 原型图
Axure RP 9最新版软件及汉化包下载 https://www.axure.com.cn/78629/ 点击下载 lang语言包放在根目录即可 Axure各种版本注册码 | 最新Axure R ...
- P2057 [SHOI2007]善意的投票 (最大流)
题目 P2057 [SHOI2007]善意的投票 解析 网络流的建模都如此巧妙. 我们把同意的意见看做源点\(s\),不同意的意见看做汇点\(t\). 那我们\(s\)连向所有同意的人,\(t\)连向 ...
- 移动像素的px ,dp/pt,dpr的关系
一:基础知识 px:逻辑像素,浏览器使用的抽象单位 dp,pt:设备无关像素 也叫物理像素 dpr:devicePixelRatio 设备像素缩放比 计算公式:1px=(dpr)^2*dp; ipho ...