F - Too Many Segments (easy version) (CodeForces - 1249D1)

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 j such that li≤j≤ri.

The integer point is called bad if it is covered by strictly more than kk 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 m (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 

 这一题是删除一个坏点如果一个点被覆盖超过k次,它就是坏点,此时删除最少的点,使这个点不是坏点。

这一题的难点就是排序删点,要删长的点,要删覆盖超过k次最多的点;

所以不好排序

 此时可以选择 删一次排一次,更新一次,

这个题的格式和其他题不一样,要额外注意一下。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int book[1010],b[1000];
struct node
{
    int x,y,z,s;

} a[10000];

int cmp(node l,node r)
{
    return l.s>r.s;
}
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    memset(book,0,sizeof(book));
    for(int i=0; i<n; i++)
    {
        scanf("%d %d",&a[i].x,&a[i].y);
        a[i].z=i+1;
        for(int j=a[i].x; j<=a[i].y; j++)
        {
            book[j]++;
        }
    }
    for(int i=0; i<n; i++)
    {
        int ans=0;
        for(int j=a[i].x; j<=a[i].y; j++)
            if(book[j]>m)
            ans+=book[j]-m;
            a[i].s=ans;
    }
    sort(a,a+n,cmp);
    int k=0,w=0;
    while(a[k].s>0)
    {
        for(int i=a[k].x; i<=a[k].y; i++)
        {
            book[i]--;
        }
        b[w++]=a[k++].z;
        for(int i=k;i<n;i++)
        {
            int sum=0;
            for(int j=a[i].x;j<=a[i].y;j++)
                if(book[j]>m)
                sum+=book[j]-m;
            a[i].s=sum;
        }
        sort(a+k,a+n,cmp);
    }
    sort(b,b+w);
    printf("%d\n",w);
    for(int i=0; i<w; i++)
        printf("%d ",b[i]);
    
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 线段相交问题是计算几何学中的常见问题,主要目标是确定两个给定线段是否相交。在解决这个问题时,我们可以使用几何知识和数学方法,下面是一种常见的解决方案: 首先,我们可以将每个线段表示为两个端点的坐标。对于线段AB,我们可以表示为A(x1, y1)和B(x2, y2)。同样的,对于线段CD,我们可以表示为C(x3, y3)和D(x4, y4)。 然后,我们可以利用一系列关系来判断线段是否相交。首先,我们可以通过比较两个线段的最小和最大x坐标来判断它们是否在同一平面上。如果线段AB的最小x坐标大于线段CD的最大x坐标,或者线段AB的最大x坐标小于线段CD的最小x坐标,则可以判断它们不会相交。 接下来,我们可以利用向量的叉积来判断两个线段是否共线。我们可以计算向量AB和向量AC的叉积以及向量CD和向量CA的叉积。如果这两个叉积乘积小于0,则可以判断线段AB和线段CD相交。 最后,我们需要考虑一些特殊情况,例如两个线段共线但没有重叠部分的情况,或者两个线段有一个公共端点的情况。这些情况可以通过包含更多的条件来进一步判断。 通过以上的方法,我们可以相对准确地判断两个线段是否相交。这个问题在计算几何学和计算机图形学中有广泛的应用,例如在碰撞检测、路径规划和游戏开发中都可以使用到。 ### 回答2: line-segments-intersect是一个用于确定两个线段是否相交的算法。这个算法的目标是判断给定的两个线段是否存在交点,若存在,则认为两个线段相交,否则认为它们不相交。 这个算法可以通过以下步骤来实现: 1. 首先,我们需要确定每个线段的两个端点的坐标。假设第一个线段的端点分别为A(x1, y1)和B(x2, y2),第二个线段的端点分别为C(x3, y3)和D(x4, y4)。 2. 接下来,我们需要利用线段AB的斜率和CD的斜率来判断它们是否平行。如果两条线段的斜率相等,那么它们是平行的,此时它们不会相交。 3. 如果线段AB和CD不平行,我们进一步判断它们是否相交。我们可以使用线段的方程来计算两条线段的交点。如果两条线段的交点的x坐标和y坐标都在两个线段的范围内,则认为它们相交。 4. 如果以上条件都不满足,则认为两条线段不相交。 通过以上步骤,我们可以确定两个线段是否相交。这个算法可以在计算机程序中实现,并可以用于各种应用场景,如计算几何问题、计算路径交叉等。但需要注意的是,线段的相交判断需要考虑特殊情况,如端点重合、线段长度为0等,以保证算法的准确性和稳定性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值