zoukankan      html  css  js  c++  java
  • CodeForces 306B

    //#include<bits/stdc++.h>
    #include<algorithm>
    #include<stdio.h>
    #include<iostream>
    using namespace std;
    const int maxx=1000000*2+10;
    struct Node
    {
        int a,l;
        int num;
    } op[maxx];
    int use[maxx];
    bool cmp(Node a,Node b)
    {
        if(a.a!=b.a) return a.a<b.a;
        else if(a.a==b.a) return a.l>b.l;
        return a.num<b.num;
    }
    int main()
    {
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=0; i<m; i++)
        {
            scanf("%d%d",&op[i].a,&op[i].l);
            op[i].num=i+1;
        }
        sort(op,op+m,cmp);
        int  right=op[0].a+op[0].l;
        use[op[0].num]=1;
        int incl=right;
        int preid=0;
        int ans=1;
        for(int i=1; i<m; i++)
        {
            if(op[i].a>incl)
            {
                if(preid)
                {
                    use[preid]=1;
                    incl=right;
                    preid=0;
                    i--;
                    ans++;
    
                }
                else
                {
                    preid=0;
                    use[op[i].num]=1;
                    right=op[i].a+op[i].l;
                    incl=right;
                    ans++;
                }
            }
            else if(op[i].a+op[i].l>right)
            {
    
                right=op[i].a+op[i].l;
                preid=op[i].num;
            }
        }
        if(preid)
        {
            ans++;
            use[preid]=1;
        }
        printf("%d
    ",m-ans);
        if(m-ans)
            for(int i=1; i<=m; i++)
                if(!use[i]) printf("%d ",i);
        return 0;
    
    }
    /*100 6
    1 100
    2 20
    3 10
    5 10
    6 1
    2 5*/
    View Code
     H
    Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    A process RAM is a sequence of bytes that are indexed from 1 to n. Polycarpus's program contains such instructions as "memset", that is, the operations of filling memory cells on a segment with some value. The details are: the code only contains m instructions that look like "set13 a_i l_i". Instruction i fills a continuous memory segment of length li, starting from cell number ai, (that it cells with numbers ai, ai + 1, ..., ai + li - 1) with values 13.

    In Polycarpus's code, the optimizer's task is to remove the maximum number of instructions from his code in such a way that the remaining instructions set value 13 in all the memory bytes that got this value from the code before the optimization. Also, the value 13 should be set only in the memory bytes that got this value from the code before the optimization. Your task is to implement the optimizer for such program.

    Input

    The first line contains integers n and m (1 ≤ n ≤ 2·106, 1 ≤ m ≤ 2·105) — the number of bytes (memory cells) and the number of instructions in Polycarpus's code. Then m lines follow, each line contains a pair of integers aili (1 ≤ ai ≤ n, 1 ≤ li ≤ n - ai + 1).

    Output

    Print in the first line the sought maximum number of instructions that can be removed from the code. In the second line print the numbers of the instructions. The instructions are numbered from 1 to m in the order they appeared in the input. If there are multiple solutions, print any of them.

    Sample Input

    Input
    10 4
    3 3
    3 1
    4 1
    9 2
    Output
    2
    2 3
    Input
    1 1
    1 1
    Output
    0


    按照起点,路径长度排序。然后贪心,每次选择覆盖最大的一个边,知道遍历完所有的边。判断最后一个边应不应该加入。
  • 相关阅读:
    记录JavaScript的util.js类库
    Shiro登录中遇到了问题
    【转载】JavaScript导出Excel
    react-router
    react 表单
    html5定位getLocation()
    html5存储方式localstorage和sessionStorage
    position导致Safari工具栏不自动隐藏
    input type="datetime-local" 时placeholder不显示
    vuex(1.0版本写法)
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5411138.html
Copyright © 2011-2022 走看看