rand函数和srand函数
先我们要对rand&srand有个总体的看法:srand初始化随机种子,rand产生随机数,下面将详细说明。
1、rand(产生随机数)
表头文件: #include
定义函数 :int rand(void)
函数说明 :
因为rand的内部实现是用线性同余法做的,他不是真的随机数,只不过是因为其周期特别长,所以有一定的范围里可看成是随机的,ran...
分类:
其他好文 时间:
2015-05-11 10:51:45
阅读次数:
160
time
这个用的最多就是随机数的时候,现在用一用其他特性.#include
#include int main()
{
time_t sec; ///typedef long time_t
struct tm * curTime; sec = time(NULL); ///获取时间,从1970.1.1到现在...
分类:
编程语言 时间:
2015-05-11 10:51:10
阅读次数:
138
这里写代码片#include
#include
using namespace std;template
class BSTNode
{
public:
Type data;
BSTNode *left;
BSTNode *right;
BSTNode...
分类:
编程语言 时间:
2015-05-11 10:48:43
阅读次数:
177
代码: 1 #include 2 #include 3 4 using namespace std; 5 6 int length = 9; 7 8 bool isValidSudoku(vector>& board) 9 {10 int flag[9];11 memset(...
分类:
其他好文 时间:
2015-05-11 10:41:20
阅读次数:
115
题意:有N(1 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0x...
分类:
编程语言 时间:
2015-05-11 10:41:10
阅读次数:
128
#include "apue.h" (c程序添加的头文件)1. 超级用户权限登入 #cd /usr/include 2. 将apue.h和error.c两个文件copy到该目录下。(apue.h位于 your_apue_path/inlcude ; error.c位于your_apue_pat...
分类:
其他好文 时间:
2015-05-11 10:26:04
阅读次数:
120
#include int binSearch(int, int, int);main(){ int i, n = 10, x = 7; //这里假设把数组a[]定义为a[n],是错误的,不能定义变长数组。 int a[10]; printf("Please enter your nu...
分类:
编程语言 时间:
2015-05-11 10:21:06
阅读次数:
105
C++中从指定区域分配内存:
#include
using namespace std;
const int buf(1024);
char buffer[buf]={0}; //开辟静态区域
//p1,p3作为指针变量在栈区,存储的地址指向堆区
//手动释放内存
//p2,p4作为指针变量在栈区,存储的地址指向静态区
//自动释放内存,用于分配用完了就不会再用的数据
//避免内存泄漏,...
分类:
编程语言 时间:
2015-05-11 09:08:51
阅读次数:
186
分析:先根据询问求出每个纵向区间的最小公倍数(一列算一个区间),在根据询问判断每个横向区间的最大公约数是否和询问相同,若都相同则输出最终结果,否则不存在。
#include
using namespace std;
int a[1005];
struct NODE
{
int l,r,gcd;
} GCD[1005];
int gcd(int x,int y)
{
return ...
分类:
其他好文 时间:
2015-05-11 09:07:24
阅读次数:
180
编写一个程序实现字梯游戏。其中,单字母替换的值为1,而单字母的删除或添加的值p>0(p值由使用者指定)。#include
#include
#include
#include
#include using namespace std;const int INFINTY = 99999;struct Verte...
分类:
其他好文 时间:
2015-05-11 09:05:38
阅读次数:
117