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/ ...
随机推荐
- delphi 取json中数组的值(ISuperArray)
{ "action": "******", "data": [ { "Info1": { "ID": ...
- 13本热门书籍免费送!(Python、SpingBoot、Entity Framework、Ionic、MySQL、深度学习、小程序开发等)
七月第一周,网易云社区联合清华大学出版社为大家送出13本数据分析以及移动开发的书籍(Python.SpingBoot.Entity Framework.Ionic.MySQL.深度学习.小程序开发等) ...
- UIView 动画
1.UIView 动画 核心动画 和 UIView 动画 的区别: 核心动画一切都是假象,并不会真实的改变图层的属性值,如果以后做动画的时候,不需要与用户交互,通常用核心动画(转场). UIView ...
- hosts是什么意思?Hosts文件有什么作用和功能?
hosts是什么意思?Hosts文件有什么作用和功能? 熟悉网络的朋友们都会用到hosts文件,针对还不清楚hosts是什么意思以及hosts文件有什么功能和作用?针对此问题,本文就为大家进行解答 ...
- python函数作用域,闭包,装饰器
第一:函数作用域: L:local 函数内部作用域 E:enclosing 函数内部与内嵌函数之间(闭包) G:global 全局作用域 B:build_in ...
- 题解 P1534 【不高兴的津津(升级版)】
题目链接 不算太难.就是题目有歧义. wa了好几次才发现.上一天要是小于8的话.结算是昨天一个负值在加上今天课时数.再减去8.233.... 而不是上一天小于8个小时.就清零了..大家要注意(ps:题 ...
- 1.1、Logistics Regression模型
1.线性可分VS线性不可分 对于一个分类问题,通常可以分为线性可分与线性不可分两种 .如果一个分类问题可以使用线性判别函数正确的分类,则称该问题为线性可分.如图所示为线性可分,否则为线性不可分: 下图 ...
- AngularJS 1.x系列:AngularJS服务-Service
1. AngularJS服务 AngularJS可注入类型包括:Service.Factory.Provider.Value及Constant. 2. Service AngularJS Servic ...
- 二分答案 & 洛谷 P2678 跳石头
首先让我们先学一下二分答案这个东西... 二分答案,肯定与二分有关,还与可能是答案的东西有关... 二分答案的准确定义: 二分答案是指在答案具有单调性的前提下,利用二分的思想枚举答案,将求解问题转 ...
- 对KMP算法通过代码生成next数组理解
本文是根据考研数据结构2019版天勤高分笔记理解编写的: 首先给出代码: 1 void getnext(Str substr,int next[]){ 2 int i=0,j=0; 3 next[1] ...