zoukankan      html  css  js  c++  java
  • HDU

    There are N schedules, the i-th schedule has start time i  si and end time i  ei (1 <= i <= N). There are some machines. Each two overlapping schedules cannot be performed in the same machine. For each machine the working time is defined as the difference between timend  timeend and timstart  timestart , where time_{end} is time to turn off the machine and timstart  timestart is time to turn on the machine. We assume that the machine cannot be turned off between the timstart  timestart and the timend  timeend .
    Print the minimum number K of the machines for performing all schedules, and when only uses K machines, print the minimum sum of all working times.

    InputThe first line contains an integer T (1 <= T <= 100), the number of test cases. Each case begins with a line containing one integer N (0 < N <= 100000). Each of the next N lines contains two integers i  si and i  ei (0<=<<=1e9(0<=si<ei<=1e9) .OutputFor each test case, print the minimum possible number of machines and the minimum sum of all working times.Sample Input

    1
    3
    1 3
    4 6
    2 5

    Sample Output

    2 8

    题意:有N个任务,每个任务有自己的起始时间和结束时间,问至少多少个机器可以完成这些任务,使其满足每台机器的任务没有时间交集。

    思路:直接贪心,每次找完成时间<=当前任务起始时间的最大的一台机器,如果没有,则弄一台新的机器。

    主要是要注意set的二分用s.lower_bound(x),优于lower_bound(s.begin(),s.end(),x);

    #include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(int i=a;i<=b;i++)
    using namespace std;
    multiset<int>s;
    multiset<int>::iterator it;
    pair<int,int>a[100010];
    int main()
    {
        int T,N,K; ll ans;
        scanf("%d",&T);
        while(T--){
            scanf("%d",&N); K=0; ans=0; s.clear();
            rep(i,1,N) scanf("%d%d",&a[i].first,&a[i].second);
            sort(a+1,a+N+1);
            rep(i,1,N){
                if(s.empty()||(*s.begin())>a[i].first) {
                    s.insert(a[i].second); K++; ans-=a[i].first;
                }
                else{
                    it=s.upper_bound(a[i].first);
                    it--;
                    s.erase(it); s.insert(a[i].second);
                }
            }
            for(it=s.begin();it!=s.end();it++) ans+=(*it);
            printf("%d %lld
    ",K,ans);
        }
        return 0;
    }
  • 相关阅读:
    Altium Designer中各层的含义
    国外现在有哪些众筹网站呢?
    C# 代码 手工 配置 Log4Net 2种方法
    Windows 7 里进程管理器里面的各列是什么含义?主要是和内存有关的内存-专用工作集,内存-工作集,内存-提交大小???
    C# .Net 下 x86使用大内存的处理
    CV学习日志:CV开发之关联Gazebo/Webots/ROS2
    CV学习日志:CV开发之Windows10环境搭建
    CV学习日志:CV开发之Ubuntu2004和WLS2环境搭建
    ROS2学习日志:ROS2Cartgrapher使用与调试
    ROS2学习日志:QoS要点总结
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9810861.html
Copyright © 2011-2022 走看看