题意

给多组线段,而每一个点的覆盖次数不超过K,每次可去除一个线段,问最少去多少线段以及线段的位置。
The only difference between easy and hard versions is constraints.

You are given nn segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The ii-th segment is [li;ri] (li≤ri) and it covers all integer points jj such that li≤j≤ri.

The integer point is called bad if it is covered by strictly more than k segments.

Your task is to remove the minimum number of segments so that there are no bad points at all.

Input
The first line of the input contains two integers nn and kk (1≤k≤n≤200) — the number of segments and the maximum number of segments by which each integer point can be covered.

The next nn lines contain segments. The ii-th line contains two integers lili and riri (1≤li≤ri≤200) — the endpoints of the ii-th segment.

Output
In the first line print one integer mm (0≤m≤n) — the minimum number of segments you need to remove so that there are no bad points.

In the second line print mm distinct integers p1,p2,…,pm(1≤pi≤n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them.

Examples
Input
7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9
Output
3
1 4 7
Input
5 1
29 30
30 30
29 29
28 30
30 30
Output
3
1 2 4
Input
6 1
2 3
3 3
2 3
2 2
2 3
2 3
Output
4
1 3 5 6

官方题解:

In this problem, the following greedy solution works: let’s find the leftmost point covered by more than kk segments. We should fix it somehow. How to do it? Let’s find some segment that was not removed already, it covers this point and its rightmost end is maximum possible, and remove this segment.
You can implement it in any time you want, even in O(n3) naively.

百度翻译:

在这个问题中,下面的贪婪解决方案是有效的:让我们找到被超过k段覆盖的最左边的点我们应该设法解决它。怎么做?让我们找到一些尚未被删除的段,它覆盖了这一点,它的最右边是最大可能的,并删除这个段。
你可以在任何时候实现它,即使是在O(n3)中。

思路

用差分数组找到每个点的覆盖次数,若超过k次则去掉几个右边较大的(因为是从左到右,所以不用考虑左边)

AC代码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=300;
int n,k,d[N],num;
struct node
{int u,v;
} s[N];
int main()
{while(~scanf("%d%d",&n,&k)){memset(d,0,sizeof(d));int mx=-1;for(int i=1; i<=n; i++)/*差分数组*/{scanf("%d %d",&s[i].u,&s[i].v);mx=max(mx,s[i].u);mx=max(mx,s[i].v);d[s[i].u]++;d[s[i].v+1]--;}for(int i=1; i<=mx; i++)d[i]+=d[i-1];  //差分求每个点被覆盖值int book[N];memset(book,0,sizeof(book));int flag=0;num=0;for(int j=1; j<=mx; j++){while(d[j]>k){flag=1;int tab=0;for(int i=1; i<=n; i++)/*从n条边中找到i所处的线段,并在所有的线段中找到最右边最大的那个线段*/{if(book[i]==0&&s[i].u<=j&&j<=s[i].v&&(tab==0||s[i].v>s[tab].v))tab=i;}if(tab==0)break;for(int i=s[tab].u; i<=s[tab].v; i++)d[i]--;book[tab]=1;num++;}}if(flag==0)printf("0\n");else{printf("%d\n",num);for(int i=1; i<=n; i++)if(book[i])printf("%d ",i);printf("\n");}}return 0;
}

Too Many Segments (easy version) CodeForces - 1249D1(贪心+差分)相关推荐

  1. Too Many Segments (hard version) CodeForces - 1249D2(贪心+容器vector+set)

    题目 给多组线段,而每一个点的覆盖次数不超过K,每次可去除一个线段,问最少去多少线段以及线段的位置. The only difference between easy and hard version ...

  2. Skyscrapers (easy version)CodeForces - 1313C1(暴力)

    This is an easier version of the problem. In this version n≤1000 The outskirts of the capital are be ...

  3. Social Network (easy version)

    Social Network (easy version) CodeForces 1234B1 这是一道我曾经训练时做过的一道题,为了应对上面的要求指标我不得不把它掏了出来(doge),这道题还是有点 ...

  4. Codeforces Round #579 (Div. 3) F1. Complete the Projects (easy version) 排序 + 贪心

    传送门 文章目录 题意: 思路: 题意: 思路: 比较直观的想法就是对于bi≥0b_i\ge0bi​≥0的项目,我们将aia_iai​从小到大排序,让后依次加bib_ibi​,如果有取不到的,显然就无 ...

  5. CodeForces - 1543D1 RPD and Rap Sheet (Easy Version)(异或+交互)

    题目链接:点击查看 题目大意:交互题猜密码,设原密码为 xxx,猜的密码为 yyy,如果没猜到,密码会自适应变成 zzz,满足 x⊕z=yx \oplus z=yx⊕z=y ,最多猜 nnn 次 题目 ...

  6. Codeforces Round #828 (Div. 3) E1. Divisible Numbers (easy version) 解题报告

    原题链接: Problem - E1 - Codeforces 题目描述: This is an easy version of the problem. The only difference be ...

  7. 【CodeForces 1255E1 --- Send Boxes to Alice [Easy Version]】

    [CodeForces 1255E1 --- Send Boxes to Alice [Easy Version]] Description This is the easier version of ...

  8. C1. Make Nonzero Sum (easy version)【Codeforces Round #829 (Div. 2】

    Codeforces Round #829 (Div. 2)中C1题目 Codeforces比赛记录 文章目录 题目链接: 一.C1. Make Nonzero Sum (easy version) ...

  9. CodeForces Round #730 D1. RPD and Rap Sheet (Easy Version)题解

    Codeforces Round #730 (Div. 2) 题意: t组数据,每组给一个n和k,(easy version里面k=2) 每一次系统会输入一个初始的密码(初始密码是一个在[0,n−1] ...

最新文章

  1. 上海.NET技术交流会
  2. 使用 Tye 辅助开发 k8s 应用竟如此简单(三)
  3. element实现动态路由+面包屑
  4. nginx php 跨域访问权限,nginx + php 实现跨域请求填坑笔记
  5. java面板换一个斜的圆形_java – 如何从底部设计圆形视图?
  6. 基于百度AI+jquery-webcam+servlet实现人脸识别登录,兼容各主流浏览器
  7. Qt4_快速设计对话框
  8. ES6-异步async await学习
  9. Autodesk 3DSMax 2012 安装说明
  10. JEB动态调试debug模式
  11. 【hexo】fluid中文乱码问题解决
  12. 软件项目管理 需求管理
  13. 谷歌浏览器html播放音乐,谷歌浏览器听歌插件:用Listen1听歌超方便!‖干货大放送...
  14. vue中的浏览量_vue项目中使用百度统计
  15. 链表上手代码---表头插入
  16. vue+element表格 苹果自带浏览器兼容问题
  17. 一次失败的j2v8集成
  18. matplotlib基础绘图命令之pie
  19. 租一个月的云服务器要花费多少?
  20. 危害网络计算机安全罪判刑几年,帮助信息网络犯罪活动行为涉嫌成立犯罪的一般判刑多少年...

热门文章

  1. LeetCode之Rotate Array
  2. 浅谈C++类(1)--概念和构造函数
  3. python函数返回多个值时的数据类型是_Python3 注释多个返回值的函数类型
  4. 基于python的随机森林回归实现_随机森林理论与python代码实现
  5. “中科院博士后当辅警”,网友却吵翻了:家里有矿?
  6. 各种机械原理动态图,看完脑洞大开,绝对涨姿势!
  7. 假期别在家里要发霉了?可以靠他们度过无聊时光
  8. 入门机器学习,开启人工智能大门!
  9. 大数据分析苏轼,你没看错,这些都是小学生完成的
  10. java 正则匹配引号_java 正则 贪婪匹配 匹配sql语句中的引号内容