Kattis downtime

链接:https://open.kattis.com/problems/downtime

题意:n个要解决的进程,每个服务器可以解决k个进程,每个进程花费1000MS,给出n个进程的开始时间,问最少要几个服务器

思路:我们可以求出每个进程的区间,然后看我们可以不重叠的解决多少个进程

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 struct node{
 5     int x;
 6     int y;
 7 }a[200005];
 8 bool cmp(node p,node q){
 9     if(p.x==q.x) return p.y<q.y;
10     return p.x<q.x;
11 }
12 int main(){
13     int n,k;
14     scanf("%d%d",&n,&k);
15     int x,l=0;
16     for(int i=1;i<=n;i++){
17         scanf("%d",&x);
18         a[++l].x=x; a[l].y=1;
19         a[++l].x=x+1000;a[l].y=-1;
20     }
21     sort(a+1,a+1+l,cmp);
22     int Max=0,sum=0;;
23     for(int i=1;i<=l;i++){
24       // cout<<a[i].x<<" "<<a[i].y<<endl
25         if(a[i].y==-1) {
26             sum--;
27         }
28         else sum++;
29         Max=max(Max,sum);
30     }
31     if(Max%k!=0) Max=Max/k+1;
32     else Max=Max/k;
33     cout<<Max<<endl;
34     return 0;
35 }

 

posted on 2017-07-23 19:15  hhhhx  阅读(114)  评论(0编辑  收藏  举报

导航