zoukankan      html  css  js  c++  java
  • 模拟垃圾分布

    // TestRandomGC.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <vector>
    #include <algorithm>
    #include <iostream>
    #include <ctime>
    #include <stdio.h>
    #include <string>
    
    using namespace std;
    
    /* 已知跑了20个小时后,垃圾量的分布情况,20%垃圾量的档位有22%,22%-50%垃圾量的比较平均了都是5%左右,52的%垃圾量有1%
        我们要实现一个可以配置的表(垃圾量分布图),配置不同垃圾量的占比是多少。我们就按照这个表,去随机生成这种垃圾量占比。*/
    unsigned int randArrays[100] = {20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 
                                                           20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 
                                                           20, 20, 22, 22, 22, 22, 24, 24, 24, 24,
                                                           26, 26, 26, 26, 28, 28, 28, 28, 28, 30,
                                                           30, 30, 30, 30, 32, 32, 32, 32, 32, 34,
                                                           34, 34, 34, 34, 36, 36, 36, 36, 36, 38,
                                                           38, 38, 38, 38, 40, 40, 40, 40, 40, 42,
                                                           42, 42, 42, 42, 42, 44, 44, 44, 44, 44,
                                                           44, 46, 46, 46, 46, 46, 46, 48, 48, 48,
                                                           48, 48, 48, 48, 48, 50, 50, 50, 50, 52};
    
    void initVector(vector<unsigned int> &vec, unsigned int size) 
    {
        srand(unsigned(time(NULL)));
        for(unsigned int i =0; i < size; i++)
        {
            int randNum = rand()%100;/* 0-99的随机数作为垃圾量分布图的下标*/
            vec.push_back(randArrays[randNum]);
        }
    }
    
    void printVector(vector<unsigned int> vec)
    {
        vector<unsigned int>::iterator it = vec.begin();
        for(; it != vec.end();++it)
        {
            printf("%d,", *it);
        }
        cout<<endl;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        vector<unsigned int> vect;
        initVector(vect, 100);
        cout<<"before sort"<<endl;
        printVector(vect);
        sort(vect.begin(), vect.end());
        cout<<"after sort"<<endl;
        printVector(vect);
        return 0;
    }
  • 相关阅读:
    mysql--------常用命令
    PHP--------微商城实现微信授权登录
    mysql--------命令来操作表
    PHP--------解决网址URL编码问题
    php-----utf8和gbk相互转换
    javascript遍历json对象数据的方法
    PHP-----------HTTP请求的第三方接口
    PHP------数组和对象相互转化,stdClass Object转array
    include与require的区别
    PHP中exit()与die()的区别
  • 原文地址:https://www.cnblogs.com/liuzc/p/6690976.html
Copyright © 2011-2022 走看看