zoukankan      html  css  js  c++  java
  • 【NOIP2010】【Luogu1190】接水问题(给定顺序的模拟)

    problem

    题意:

    • 有n个人,每个人接水wi
    • 有m个水龙头,每个水龙头每秒供水1
    • 求n个人接完水要多少时间

    注意:

    • 人按编号1~n接水(坑点,顺序确定)
    • 换人过程没有浪费
    • n < m 多余水龙头关闭

    范围:

    • n < 1e4, m < 1e3, wi < 100

    solution

    规则已经确定了啊,不是求最优解,就是模拟这个过程得到答案而已。
    1、用小根堆q存储每个水龙头剩余时间,每次取出剩余最少的把他加上wi放回去。
    2、最后小根堆中值最大的就是接水时间。
    复杂度O(nlogn).

    codes

    #include<iostream>
    #include<algorithm>
    #include<queue>
    using namespace std;
    const int maxn = 110;
    int n, m, a[maxn];
    priority_queue<int,vector<int>,greater<int> >q;
    int main(){
        cin>>n>>m;
        for(int i = 1; i <= n; i++){//因为顺序固定了
            if(i <= m){//最少的是0,直接丢
                int x;  cin>>x;  q.push(x);
            }else{//取出最少的加进去
                int x;  cin>>x;
                int t = q.top(); q.pop();
                t += x;
                q.push(t);
            }
        }
        int ans = 0;
        while(q.size()!=1)q.pop();
        ans = q.top();
        cout<<ans<<'
    ';
        return 0;
    }
    
  • 相关阅读:
    第五周的学习进度情况
    周末经历之小体会
    构建之法阅读笔记5
    第四周的学习进度情况
    hashMap中如何形成循环链表的?
    代理模式
    sharing-jdbc实现读写分离及分库分表
    分库分表
    读写分离实现方式
    MySQL主从复制
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444633.html
Copyright © 2011-2022 走看看