码迷,mamicode.com
首页 > 其他好文 > 详细

code forces1249D Too Many Segments

时间:2019-11-07 23:45:36      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:main   ==   mes   art   struct   ons   nod   tps   max   

大佬连接::https://blog.csdn.net/weixin_43847416/article/details/102749985

题意::删除最少数量的区段使每个整数点的覆盖次数不大于K

思路::

以区间左端点为头,右端点由小到大排序,如果端点相同,按标号存入。

从头开始遍历每个点,判断每个点上覆盖次数,大于k时删除最长的那个区间。

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int maxn=2e5+5;
 5 struct node{
 6     int r,index;
 7     node(){}
 8     node (int  rr,int ii ):r(rr),index(ii){}
 9     bool operator < (const node &rh)const{
10         if(r==rh.r){return index<rh.index;}
11         else{return r<rh.r;}
12     }
13 };
14 vector<int>ans;
15 vector<node>p[maxn];
16 
17 int main()
18 {
19     int n,k,a,b;
20     scanf("%d%d",&n,&k);
21     for(int i=1;i<=n;i++){
22         scanf("%d%d",&a,&b);
23         p[a].push_back(node(b,i));
24     }
25     set<node>s;
26     for(int i=1;i<maxn;i++){
27         while(s.size()&&(*s.begin()).r<i){s.erase(*s.begin());}
28         for(int j=0;j<p[i].size();j++){
29             s.insert(p[i][j]);
30         }
31         while(s.size()>k){
32             ans.push_back((*s.rbegin()).index);
33             s.erase(*s.rbegin());
34         }
35     }
36     int len=ans.size();
37     printf("%d\n",len);
38     for(int i=0;i<len;i++){
39         printf("%d ",ans[i]);
40     }
41     return 0;
42 }

 

code forces1249D Too Many Segments

标签:main   ==   mes   art   struct   ons   nod   tps   max   

原文地址:https://www.cnblogs.com/sj-gank/p/11816274.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!