【对拍√】

太感人了我终于会对拍了被自己菜哭

  • 随机数据生成quq
  1. #include<cstdlib> 包含rand和srand两个函数
  2. #include<ctime> 包含time函数  
  3. time(0) 返回Unix纪元(1970/1/1 0:00:00 到现在的秒数)
  4. srand((unsigned)time(0))  初始化随机种子 
  5. int random(int n) {return (long long)rand() * rand() % n; }  随机数据生成模板, 调用函数random(n) 可返回 0 ~ n-1之间的随机整数 , int范围内均能满足要求 , 如果不希望有0 的出现, 可以在后面加上1 呀qwq

  6. 若要产生随机实数, 可以先生成一个较大的随机整数, 再用它除以10 的次幂
  7. 1 int n = random(100 + 1) + 1;
    2 int m = 1000;
    3 for(int i = 1; i <= n; i++) {
    4     a[i] = random(2 * m + 1) - m;//生成负数只需要先生成一个0 ~ 2m之间的随机整数再减去m即可
    5 }//随机生成n(n <= 100)个绝对值在1000 以内的整数
  8. 随机生成树, 随机生成图咕掉

                 

猜你喜欢

转载自www.cnblogs.com/Hwjia/p/9843364.html