zoukankan      html  css  js  c++  java
  • Algs4-1.4.45优惠券收集问题

    1.4.45优惠券收集问题。用和上一题相同的方式生成随机整数。通过实验验证生成所有可能的整数值所需生成的随机数总量为~N HN 。
    答:HN表示递推关系。通过以下实验结果观察得出Hn接近于一个等差数列。
    图片
    public class E1d4d45
    {
      public static void main(String[] args)
      {
        for (int i=2;i<=100000000;i=i+i)
        {
        int[] data=new int[i];
        int count=0;
        int notRepeartCount=0;
        while (notRepeartCount<i)
        {
          int r=StdRandom.uniform(i);
          count++;
          if(data[r]==0)
          {
             notRepeartCount++;
              data[r]=1;
          }
        }//end while
        StdOut.printf("N=%9d count=%9d count/N=%3d ",i,count,count/i);
        }//end for
      }//end main
    }//end class

  • 相关阅读:
    03-spring bean
    04-spring的依赖注入
    01-课程安排
    17-注解开发
    WIN10新机必要设置记录 for 3dsmax
    ps导出svg
    VS C# 共享项目
    在Maxscript中创建.Net类型
    C# 自定义索引
    C# ?
  • 原文地址:https://www.cnblogs.com/longjin2018/p/9854603.html
Copyright © 2011-2022 走看看