随机化算法
谛听-
线上幽灵
展开
-
计算定积分
#include "iostream"#include "ctime"using namespace std;const unsigned long maxshort = 65536L;const unsigned long multiplier = 1194211693L;const unsigned long adder = 12345L;class RandomNumber{原创 2015-12-11 12:50:07 · 1421 阅读 · 0 评论 -
主元素问题--蒙特卡罗
#include "iostream"#include "ctime"#include "cmath"#include "random.h"using namespace std;int key;template<class Type>bool majority(Type T[], int n) //判断主元素的蒙特卡洛方法{ int i; RandomNumber rn原创 2015-12-11 15:00:35 · 2160 阅读 · 0 评论 -
用随机投点法计算PI值
#include "iostream"#include "ctime"#include "iomanip"using namespace std;const unsigned long maxshort = 65536L;const unsigned long multiplier = 1194211693L;const unsigned long adder = 12345L;class原创 2015-12-11 13:16:18 · 9142 阅读 · 0 评论 -
平均值法计算定积分
#include "cstdio"#include "time.h"using namespace std;const unsigned long maxshort = 65536L;const unsigned long multiplier = 1194211693L;const unsigned long adder = 12345L;class RandomNumber{ p原创 2015-12-11 12:56:12 · 10756 阅读 · 1 评论 -
随机抛硬币
#include "iostream"#include "ctime"#include "iomanip"using namespace std;const unsigned long maxshort = 65536L;const unsigned long multiplier = 1194211693L;const unsigned long adder = 12345L;class原创 2015-12-11 13:10:23 · 3455 阅读 · 0 评论 -
n皇后问题--拉斯维加斯
#include "iostream"#include "cmath"#include "cstdlib"#include "ctime"using namespace std;class Queen{public: friend void nQueen(int);private: int *x, *y; //解向量 int n; //皇后个数原创 2015-12-16 20:35:23 · 861 阅读 · 0 评论 -
素数测试--蒙特卡罗
#include "iostream"#include "ctime"#include "cmath"#include "random.h" //自己编写的头文件using namespace std;//Fermat: 如果n是素数,a是整数且不能被n整除,则a^(n-1) % n = 1//二次探测:如果n是素数,x是整数且0<x<n,则 x^2 % n = 1void power原创 2015-12-11 21:10:25 · 1544 阅读 · 0 评论 -
STL---随机数发生器
#include <iostream> #include <stdlib.h> //rand() srand()#include <time.h> using namespace std;//产生[low, high)之间的随机数double randval(double low, double high) { double val; val = ((d原创 2016-03-05 12:13:13 · 1409 阅读 · 0 评论 -
随机洗牌
//产生[low, high)之间的随机数 int randval(int low, int high) { int val; val = floor( ((double)(rand()%RAND_MAX)/RAND_MAX)*(high - low) + low); return val; }原创 2016-08-28 10:56:55 · 482 阅读 · 0 评论