- 浏览: 436275 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (158)
- J2SE (15)
- c/c++ (17)
- linux & ubuntu (20)
- js (18)
- algorithm (21)
- android (1)
- software (3)
- svn (1)
- db (6)
- other (19)
- css (5)
- go (1)
- html 5 (3)
- computer science (1)
- php (3)
- 创业 (8)
- EJB & jboss (1)
- TDD (1)
- jsp & servlet (2)
- http, tcp & ip (2)
- hibernate (1)
- json (1)
- 乐 (2)
- ps (2)
- netbeans (1)
- extjs (2)
- eclipse (4)
- 项目管理 (1)
- varnish (2)
- study abroad (1)
- python (1)
- erlang (1)
- math (1)
- shell (1)
- assembly (4)
- lucene (1)
- web (1)
- http (1)
- tcp & ip (1)
最新评论
-
yiguxianyun:
...
css li 不换行 -
stdayong:
...
netbeans 中使用 maven -
程序猿_星:
为啥会中文乱码啊
servlet 以 gzip 格式返回数据 -
huanhuan519:
感谢分享~
gdb 调试工具 -
heyl1234:
写过些js,对css还不熟。谢谢~
css li 不换行
random select
problem:
select m number from 0 - (n-1) randomly,
------
solution 1
for each number in 0 - (n-1), in increasing order, generate a random number x, using "(x%remain) < to_select" to decide will the number be choose,
until m number is choosen,
time:
o(n), when n is small, this is quick, but when n is very big, this will be very slow,
------
solution 2
use set to store choosen number, until enough,
time:
o(m*log(m))
space:
o(m)
disadvangate:
when n & m is quite closer, and n is big, this might be slow,
when m is big, will need a lot memory,
------
solution 3
init a n length array in increasing order,
mix the order of first m elements in original array,
then sort the first m elements,
then use the first m elements,
time:
o(n+m*log(m))
space:
o(n)
------
solution 4
base on solution 3,
don't init a n length array, only use a map to store first 5 m elements, and the elements that has been choose for swap with,
time:
o(m*log(m))
space:
o(m)
------
reverse select
if m*2 > n, we can choose to select n-m elements, and exclude them, the remain is m elements,
------
code:
/* @authur kuchaguangjie@gmail.com */ /** * problem: select m number from 0 - (n-1) randomly, */ #include <stdio.h> #include <stdlib.h> /** * solution 1: for each number in 0 - (n-1), in increasing order, generate a random number x, using "(x%remain) < to_select" to decide will the number be choose,until m number is choosen, * time: O(n), when n is small, this is quick, but when n is very big, this will be very slow, */ void random_m_n(const int m, const int n) { int remain = n,to_select = m,i=0; while(to_select>0) { if(rand()%remain<to_select) { printf("%d,",i); to_select--; } remain--; i++; } printf("\n"); } /** * swap 2 int value,by pointer, */ void swap(int *a,int *b) { int c = *a; *a = *b; *b = c; } /** * compare function for int */ int int_cmp(int *a,int *b) { return *a-*b; } /** * solution 2: init a n length array in increasing order, mix the order of first m elements in original array, then sort the first m elements, then use the first m elements, * time: o(n+m*log(m)) * space: o(n) */ void random_m_n_2(const int m, const int n) { int arr[n],i,swp,x; for(i=0;i<n;i++) { arr[i] = i; } for(i=0;i<m;i++) { x = rand()%n; swap(arr+i,arr+x); } qsort(arr,m,4,int_cmp); for(i=0;i<m;i++) { printf("%d,",arr[i]); } printf("\n"); } int main(){ random_m_n(30,2000); random_m_n(0,0); random_m_n(20,20); random_m_n_2(30,2000); random_m_n_2(0,0); random_m_n_2(20,20); }
------
发表评论
-
c - linkedlist
2012-05-10 14:52 1027c - linkedlist store ordere ... -
c - word counter (binary-tree)
2012-05-09 14:17 1671c - word counter (binary-tree) ... -
c - pointer is also pass by value
2012-05-09 14:13 927c - pointer is also pass by ... -
find palindromic-prime in pi
2012-04-26 18:32 1797find palindromic-prime in pi ... -
c #define
2012-04-08 13:29 2054c #define macro substitu ... -
c static
2012-04-04 21:59 1188c static static external ... -
c extern
2012-04-04 21:53 1111c extern extern, used to de ... -
int to string by specified base
2012-04-03 22:15 1034int to string by specified base ... -
sparse data structure - matrix
2011-08-18 20:03 1031sparse data structure sp ... -
max sub_sequence - c
2011-08-10 01:02 1038max sub_sequence - c /* ... -
binary search - c
2011-08-06 12:07 1045binary search - c (simple) ... -
bit_array - simple use
2011-05-28 23:47 971bit array,use less memory to de ... -
linux c udp
2011-04-01 18:02 2037linux 下可用 c 进行 udp 通信,使用 server ... -
linux c tcp
2011-04-01 18:00 3028linux 下可用 c 进行 tcp 通信,使用 server ... -
gdb 调试工具
2011-02-21 17:20 3235gdb 调试工具 gdb 概 ... -
linkedlist - java 简单实现
2011-02-11 21:29 1555linked list 链表, - ... -
queue (用 java 简单实现)
2011-02-03 01:45 4007queue ------ 结构 线性存 ... -
Medians and Order Statistics (次序统计)
2011-01-03 14:36 2776Medians and Order Statistics - ... -
counting sort
2011-01-02 20:36 1525counting sort ------ counting ... -
quick sort
2011-01-01 20:26 1152quicksort ------ quicksort ove ...
相关推荐
可以多人点名、调整点名的人数等等;Qt5.12+VS17编译器 可以直接运行,只要1分试试水
这样设置,人物就会被移动到第8格了,很简单吧,对了,如果打上randomselect就有随机选人物的功能了, 加入背景的方法: 把背景的SFF和DEF文件放到stages里 同样打开data里select.def的文件,在 [Extrastages]...
[count]返回 count 个范围为 min 到 max-1 的随机整数随机选择工具/t random select 兰州拉面 沙县小吃 黄山菜饭骨头汤...从空格分割的选项中随机选择一个UUID/t random uuid生成一个 v4 uuid/t random uuid 1生成一...
RandomListSelector 选择列表,然后从返回的列表中获取随机项目
Farthest-Point Heuristic based Initialization Methods for K-Modes Clustering,何增友,,The k-modes algorithm has become a popular technique in solving ... However, the algorithm requires random select
class RandomSelect(object): def Partition(self,a, p, r): x=a[r] i=p-1 for j in range(p, r): '''如果a[j]>x,则只需将j的值加1即可使循环不变量继续保持; 如果a[j]<=x,则将下标i的值加1,并交换a[i]和a...
This thesis proposes to employ an alternative random forest method, the variable importance measure of which can be employed to reliably select relevant predictor variables in any data set. The ...
dbms_random是oracle提供的一... select dbms_random.value from dual; SQL> select dbms_random.value from dual; VALUE ———- 0.61011338 代码如下: — FUNCTION value RETURN NUMBER; select dbms_random.value f
This is a simple random selector that can load items your Access Database in a random way. This uses an OLEDB connection an of course an Access Database. Hope this helps. Thanks :Rockby
import numpy as np import pandas as pd ... # Select random subsets of points uniformly from point set ixs = np.random.choice(n, size=(n // tree_size, tree_size), replace=False) # Add sampled trees t
:check_mark_button: Vue选择图片 Vue 2.x组件,用于从列表中选择图像 演示版 安装 # Yarn yarn add vue-select-image # NPM ... src : 'https://unsplash.it/200?random' , alt : 'Alt Image 1' }
Math.random()方法返回大于等于 0 小于 1 的一个随机数。对于某些站点来说,这个方法非常实用,因为可以利用它来随机显示一些名人名言和新闻事件。...function selectFrom(startNumber, endNumber) {
Create React App入门该项目是通过引导的。可用脚本在项目目录中,可以运行:npm start 在开发模式下运行应用程序。 打开在浏览器中查看它。 如果您进行编辑,则页面将重新加载。 您还将在控制台中看到任何棉绒错误...
简单得说,通过dbms_random包调用随机数的方法大致有4种: 1、dbms_random.normal 这个函数不带参数,能返回normal distribution的一个number类型,所以基本上随机数会在-1到1之间。 简单测试了一下,产生100000...
import random # 输入胆码 danma_input = input("请输入双色球胆码,多个号码请用逗号隔开:") danma = [int(i) for i in danma_input.split(",")] ... hong_num = random.sample(rest_num, 6 - danma_select_num)
In this work, a random vector functional link network based approach is introduced to address these issues. In the proposed system, a subset of informative features from many randomized noisy ...
Random random=new Random(); //存放结果集合 int[] result=new int[count]; for(int j=0;j;j++) { int index=random.nextInt(max); //获取当前位置 int select=(Integer)list.get(index); ...
选择随机文件 从提供的目录中选择一个随机文件: const randomFile = require('select-random-file')const dir = '/tmp/whatever'randomFile(dir, (err, file) => { console.log(`The random file is: ${...
Includes target image yctx.bmp, vector image Miss.bmp, image hidden code randlsbimghide.m file, image file reading code randlsbimgget.m, random bits select the code randinterval.m file.)
intertask communication times are random variables following certain probability distributions. Scheduling such precedence constrained stochastic tasks with communication times on a heterogeneous ...