zoukankan      html  css  js  c++  java
  • 帝国的困境:80-20法则

    #include <vector>
    #include <stdlib.h> 
    #include <time.h>
    
    using namespace std;
    
    class Person
    {
    public:
        bool consume_money() {
            if(money >= 10) {
                money -= 10;
                return true;
            } else {
                return false;
            }
        }
        void earn_money() {
            money += 10;
        }
        void show_money() {
            printf("%d	", money);
        }
    
    private:
        uint32_t money = 100;
    };
    
    int main()
    {
        vector<Person> society(10);
        srand(time(NULL));
        auto consumption_cycle = [&society] {
            for(auto &p : society) {
                bool re = p.consume_money();
                if (!re)continue;
                uint8_t producer_id = (uint8_t)(rand() % 10);
                society[producer_id].earn_money();
            }            
        };
    
        for (int i = 0; i < 100000000; i++) {
            consumption_cycle(); //100000000 cycles later
        }
    
        for (auto &p : society) {
            p.show_money();
        }
        getchar();
        return 0;
    }

    结果:

    earn_money的人是用时间为seed的纯随机分配,结果仍然是20%的人掌握了71%的财富

    真实的社会中,有能力先赚到钱的人会加大投资,掌握更多的资源,在earn_money中有更高的优先级。

    中国5000年的文明史中,一个全新王朝数百年后基本上都会崩溃,贫富差距过大是底层人民革命的根本原因。

    忧国忧民的人,大概都是看到了这个问题,又想不出办法来解决吧,你有什么好的算法可以解决这个问题吗?

  • 相关阅读:
    HTTP以及TCP协议
    分布式理论
    JAVA基础面试题
    JAVA基础面试题
    vue 中百度富文本初始化内容加载失败(编辑操作某列数据时,富文本中内容偶尔会为空)
    CodeMirror的使用方法
    JSON格式化,JSON.stringify()的用法
    promise与await的用法
    服务器端node.js
    数组扁平化
  • 原文地址:https://www.cnblogs.com/awiki/p/13781066.html
Copyright © 2011-2022 走看看