由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 如何编程实现以下简单的组合问题
相关主题
multiple random number generator编译 64/32 位的library (Linux)
help understanding code (random number)[合集] 有人用过gasdev()产生随即数吗?求救!
Question about C++ faq[合集] 面试问题
question急用:谁有C Recipe原文及代码呀?
方块里面的随机位置[合集] C++ STL question
How to generate random number in driver (build in DDK)numerical recipes in C++有人用过吗?
请教一个c++概率小程序[合集] C里面有没有现成的matrix computation as matlab?
random number generator in C++Random number generator in C++
相关话题的讨论汇总
话题: int话题: temp话题: rand话题: swap话题: chapter
进入Programming版参与讨论
1 (共1页)
m*******a
发帖数: 83
1
从10个不同的球中任意取5个球。算法如何实现呢?
q*****g
发帖数: 72
2
permutation. take first 5

【在 m*******a 的大作中提到】
: 从10个不同的球中任意取5个球。算法如何实现呢?
m*******a
发帖数: 83
3
具体算法如何实现呢? 任何语言都可以

【在 q*****g 的大作中提到】
: permutation. take first 5
q*****g
发帖数: 72
4
for (int i = 1; i <= 10; +=i)
{
int j = rand() % (10-i+1) + i; // random number between i to 10
swap(a[i],a[j]);
}
// take first 5

【在 m*******a 的大作中提到】
: 具体算法如何实现呢? 任何语言都可以
k****f
发帖数: 3794
5
你找找knuth的电子书,the art of computer programming volume 4
里面有一章就有详细介绍怎么产生排列组合的

【在 m*******a 的大作中提到】
: 具体算法如何实现呢? 任何语言都可以
m*******a
发帖数: 83
6
能具体解释一下swap吗?

【在 q*****g 的大作中提到】
: for (int i = 1; i <= 10; +=i)
: {
: int j = rand() % (10-i+1) + i; // random number between i to 10
: swap(a[i],a[j]);
: }
: // take first 5

q*****g
发帖数: 72
7
void swap(int i, int j)
{
int temp;
temp = i;
i = j;
j = temp;
}

【在 m*******a 的大作中提到】
: 能具体解释一下swap吗?
m*******a
发帖数: 83
8
I see, but if I take the first 5 of the randon arrangement, how to avoid the
repeated ones?

【在 q*****g 的大作中提到】
: void swap(int i, int j)
: {
: int temp;
: temp = i;
: i = j;
: j = temp;
: }

k****f
发帖数: 3794
9
google就有了
http://www.merriampark.com/comb.htm

the

【在 m*******a 的大作中提到】
: I see, but if I take the first 5 of the randon arrangement, how to avoid the
: repeated ones?

O******e
发帖数: 734
10

The above line is strictly speaking problematic unless you can guarantee
that the low-order bits returned by rand() are uniformly randomized.
See either Chapter 3 of Knuth or Chapter 7 of Numerical Recipes or
"man -S 3 rand" on a Linux system for the correct way of randomly
selecting integers with uniform probability.

【在 q*****g 的大作中提到】
: for (int i = 1; i <= 10; +=i)
: {
: int j = rand() % (10-i+1) + i; // random number between i to 10
: swap(a[i],a[j]);
: }
: // take first 5

a*********e
发帖数: 697
11
agree, set random seed first.

【在 O******e 的大作中提到】
:
: The above line is strictly speaking problematic unless you can guarantee
: that the low-order bits returned by rand() are uniformly randomized.
: See either Chapter 3 of Knuth or Chapter 7 of Numerical Recipes or
: "man -S 3 rand" on a Linux system for the correct way of randomly
: selecting integers with uniform probability.

1 (共1页)
进入Programming版参与讨论
相关主题
Random number generator in C++方块里面的随机位置
[合集] how to swap 2 int without using temp var.How to generate random number in driver (build in DDK)
请教个C++程序设计请教一个c++概率小程序
谁有numerical recipe in Fortran啊random number generator in C++
multiple random number generator编译 64/32 位的library (Linux)
help understanding code (random number)[合集] 有人用过gasdev()产生随即数吗?求救!
Question about C++ faq[合集] 面试问题
question急用:谁有C Recipe原文及代码呀?
相关话题的讨论汇总
话题: int话题: temp话题: rand话题: swap话题: chapter