zoukankan      html  css  js  c++  java
  • hdu 6180 Schedule

    题意:给出n个需要工作的时间区间,问最少需要几台机器,然后问机器工作的最少时间

    思路:得出最少的机器后,我们可以求出每台机器的开始时间,倒着求结束时间,减下就可以了

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 const int N=2e5+10;
     5 
     6 struct node{
     7     ll x;
     8     int type;
     9 }a[N];
    10 ll b[N];
    11 int cmp(node p,node q){
    12     if(p.x==q.x) return p.type<q.type;
    13     return p.x<q.x;
    14 }
    15 
    16 int main(){
    17     int t;
    18     cin>>t;
    19     while(t--){
    20         int n;
    21         int l=0;
    22         scanf("%d",&n);
    23         for(int i=1;i<=n;i++){
    24             scanf("%lld",&a[++l].x);
    25             a[l].type=1;
    26              scanf("%lld",&a[++l].x);
    27             a[l].type=-1;
    28         }
    29        // cout<<1<<endl;
    30         sort(a+1,a+1+l,cmp);
    31         ll sum=0;
    32         ll Max=0;
    33         int r=0;
    34         for(int i=1;i<=l;i++){
    35             if(a[i].type==1){
    36                sum++;
    37             }
    38             else sum--;
    39             if(sum>Max){
    40                 b[++r]=a[i].x;
    41                 //cout<<a[i].x<<" ";
    42             }
    43             Max=max(Max,sum);
    44         }
    45         ll ss=0;
    46         cout<<Max<<" ";
    47         ll ssum=0,MMax=0;
    48         for(int i=l;i>=1;i--){
    49             if(a[i].type==-1){
    50                 ssum++;
    51             }
    52             else ssum--;
    53             if(ssum>MMax){
    54                 ss+=a[i].x-b[r];r--;
    55             }
    56             MMax=max(MMax,ssum);
    57         }
    58         cout<<ss<<endl;
    59     }
    60 }
  • 相关阅读:
    学习python第六天
    学习python第五天
    学习python第四天
    学习python第二天
    网工学Python——模块和包
    网工学Python——初识函数
    网工学Python——常用模块
    网工学Python——基础知识
    网工学Python——目录
    Python-面向对象
  • 原文地址:https://www.cnblogs.com/hhxj/p/7424665.html
Copyright © 2011-2022 走看看