zoukankan      html  css  js  c++  java
  • poj2709

    模拟题,在合成灰色的时候,每次取当前剩余最多的三种颜色,各取1mL合成。然后重新看剩余最多的是哪三个。

    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <functional>
    #include <queue>
    using namespace std;
    
    #define MAX_COLOR_NUM 20
    
    int color_num;
    int gray_vol;
    int color_vol[MAX_COLOR_NUM];
    int ans;
    
    void input()
    {
        int max_vol = 0;
        for (int i = 0; i < color_num; i++)
        {
            scanf("%d", &color_vol[i]);
            max_vol = max(color_vol[i], max_vol);
        }
        scanf("%d", &gray_vol);
        ans = (max_vol + 49) / 50;
    }
    
    void produce_gray()
    {
        priority_queue<int> pq;
        for (int i = 0; i < color_num; i++)
            if (color_vol[i] != 0)
            {
                pq.push(color_vol[i]);
                color_vol[i] = 0;
            }
        while (pq.size() >= 3)
        {
            int a = pq.top();
            pq.pop();
            int b = pq.top();
            pq.pop();
            int c = pq.top();
            pq.pop();
            a--;
            b--;
            c--;
            gray_vol--;
            if (a)
                pq.push(a);
            if (b)
                pq.push(b);
            if (c)
                pq.push(c);
        }
        int i = 0;
        while (!pq.empty())
        {
            color_vol[i] = pq.top();
            pq.pop();
            i++;
        }
    }
    
    void work()
    {
        for (int i = 0; i < color_num; i++)
            color_vol[i] = ans * 50 - color_vol[i];
        while (1)
        {
            produce_gray();
            if (gray_vol <= 0)
                break;
            ans++;
            for (int i = 0; i < color_num; i++)
                color_vol[i] += 50;
        }
        printf("%d
    ", ans);
    }
    
    int main()
    {
        while (scanf("%d", &color_num), color_num)
        {
            input();
            work();
        }
        return 0;
    }
    View Code
  • 相关阅读:
    50个网页常用小代码
    web前端题目(持续更新)
    一步步构建大型网站架构(转)
    CentOS下配置node.js
    ajax文件上传
    test
    文件上传input简便美化方案
    String.match()与RegExp.exec()
    ie7下zindex问题
    javascript将数组插入到另一个数组中
  • 原文地址:https://www.cnblogs.com/rainydays/p/3275829.html
Copyright © 2011-2022 走看看