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/ ...
随机推荐
- android 多点触控
多点触控 1.多点触控从字面意思讲就是你用大于等于2根的手指触摸子啊手机屏幕上. Android中监听触摸事件是onTouchEvent方法,它的参数为MotionEvent,下面列举MotionEv ...
- [.net 多线程]Barrier
当需要[一组任务]并行地运行一连串的阶段,但是每一个阶段都要等待所有他任务完成前一阶段之后才能开始,可以通过Barrier实例来同步这一类协同工作.Barrier初始化后,将等待特定数量的信号到来,这 ...
- .NET Core Api 集成 swagger
废话不多讲 第一步 当然是要通过 NuGet 安装第三方插件 swagger 程序包管理器控制台,安装命令:Install-Package Swashbuckle.AspNetCore -Pre 第 ...
- C# 抽象(3)
接上章: 抽象类中有抽象方法,那么可不可以有非抽象方法呢? 答案是可以的. abstract class Human { public abstract void Think(); public ab ...
- WebJars——web端静态资源的jar包
1.WebJars介绍 Web前端使用了越来越多的JS或CSS,如jQuery,Backbone.js和Bootstrap.一般情况下,我们是将这些Web资源拷贝到Java Web项目的webapp相 ...
- 生成HTML测试报告
HTMLTestRunner是Python标准库unittest单元测试框架的一个扩展,可以生成易于使用的HTML测试报告,这个扩展很简单,只有一个HTMLTestRunner.py,下载地址:htt ...
- jQuery定位导航滚动3
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Mongoid Relationships
1:1 embedded relationship: M:1 linked relationship(one_direction): child uses belongs_to parent uses ...
- Codeforces Round #175 (Div. 2) A~D 题解
A.Slightly Decreasing Permutations Permutation p is an ordered set of integers p1, p2, ..., pn, c ...
- 最小圆覆盖 [模板] BZOJ 1337&1336
题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入输出格式 输入格式: 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi& ...