掷骰子 [英] rolling dice

查看:48
本文介绍了掷骰子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有骰子有n个边,这样n ^ m就不会破坏

int作为数据类型。当m = 4且n = 6时,结果可能是{2,5,1,2}。

在c中表示这个的好方法是什么,以便我可以通过粗暴检查案例

强制? EC

Let''s say I have m dice having n sides, such that n^m is not going to bust
int as a datatype. With m=4 and n=6, an outcome might be {2, 5, 1, 2}.
What is a good way to represent this in c so that I can check cases by brute
force? EC

推荐答案



" Elijah Cardon" < in ***** @ invalid.netwrote in message

news:12 ************* @ corp.supernews.com ...

"Elijah Cardon" <in*****@invalid.netwrote in message
news:12*************@corp.supernews.com...

假设我有骰子有n个边,这样n ^ m就不会破坏

int作为数据类型。当m = 4且n = 6时,结果可能是{2,5,1,2}。

在c中表示这个的好方法是什么,以便我可以通过
蛮力? EC
Let''s say I have m dice having n sides, such that n^m is not going to bust
int as a datatype. With m=4 and n=6, an outcome might be {2, 5, 1, 2}.
What is a good way to represent this in c so that I can check cases by
brute force? EC



取决于你的meory


typedef struct

{

int m;

int n;

int * roll; / *用malloc分配骰子* /

} DICEROLL;


如果你有内存可以燃烧,这是显而易见的方法。

但是你已经知道了卷组中所有可能的骰子。所以你可以通过模数和除法来从索引号生成滚动。

-
www.personal.leeds.ac.uk/~bgy1mm

免费下载游戏。

Depends on your meory

typedef struct
{
int m;
int n;
int *roll; /* allocated dice with malloc */
} DICEROLL;

Is the obvious way if you have memory to burn.
However you already know all the possible dice in the roll set. So you can
generate the rolls from an index number by taking modulus and dividing.
--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.


Elijah Cardon写道:
Elijah Cardon wrote:

让我们说我的骰子有n个边,这样n ^ m不会破坏

int作为数据类型。当m = 4且n = 6时,结果可能是{2,5,1,2}。

在c中表示这个的好方法是什么,以便我可以通过粗暴检查案例

强制? EC
Let''s say I have m dice having n sides, such that n^m is not going to bust
int as a datatype. With m=4 and n=6, an outcome might be {2, 5, 1, 2}.
What is a good way to represent this in c so that I can check cases by brute
force? EC



想到的一种方法是n-adic数字;开始你的结果

为0(即必要时减1),然后你得到一个范围的数字

从0到n-1。这可以(使用^表示权力)代表



a [m-1] * n ^(m-1)+ .... + a [1 ] * n ^ 1 + a [0] * n ^ 0。

即以上可以表示为

(2-1)* 216 +(5-1)* 36 +(1-1)* 6 +(2-1)* 1

在大多数情况下,我宁愿使用包含数字的数组 - 对于

很多n,它更容易调试。如果你真的希望能够将它变成一个int,那么你可以在其余的时候尽快完成

的工作。

干杯

Michael

-

电子邮件:我的是/ at / gmx / dot / de地址。

One way that comes to mind are n-adic numbers; start your results
at 0 (i.e. subtract 1 if necessary), then you get digits of a range
from 0 to n-1. This can be (using ^ to express powers) represented
as
a[m-1]*n^(m-1)+....+a[1]*n^1+a[0]*n^0.
I.e. the above can be represented as
(2-1)*216+(5-1)*36+(1-1)*6+(2-1)*1
In most cases, I''d rather use an array containing the digits -- for
many n, it is easier to debug. If you then really want to be able
to squeeze it into an int, then you can do it as soon as the rest
works.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


Malcolm发布:
Malcolm posted:

typedef struct

{

int m;

int n;

int * roll; / *用malloc分配骰子* /

} DICEROLL;
typedef struct
{
int m;
int n;
int *roll; /* allocated dice with malloc */
} DICEROLL;



我强烈建议只为宏和宏使用ALL CAPS。


-


Frederick Gotham


I strongly advocate the use of ALL CAPS for macros and for macros only.

--

Frederick Gotham


这篇关于掷骰子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆