zoukankan      html  css  js  c++  java
  • 【CF306B】Optimizer

    题目描述

    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 ii fills a continuous memory segment of length (l_{i}), starting from cell number (a_{i}) , (that it cells with numbers (a_{i},a_{i+1},...,a_{i+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.

    题目大意

    (n) 个区间,要删除尽量多的区间,使原来区间覆盖到的数删除后也都覆盖到。

    思路

    先选定第一个区间,再对于起点在当前区间中的区间,选出一个右端点最远的作为下一个区间,这样不断选来覆盖

    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    const int maxn = 2e6 + 10;
    const int inf = 99999999;
    int n,m,p,now,maxv,d[maxn],mx[maxn],num[maxn],ans[maxn];
    bool cho[maxn];
    int main() {
    	scanf("%d%d",&n,&m);
    	for (int i = 1,l,r,s;i <= m;i++) {
    		scanf("%d%d",&l,&s);
    		r = l+s-1;
    		d[l]++; d[r+1]--;
    		if (r > mx[l]) { mx[l] = r; num[l] = i; }
    	}
    	for (int i = 1;i <= n;i++) d[i] += d[i-1];
    	for (int i = 1;i <= n;i++) {
    		if (mx[i] > maxv) { maxv = mx[i]; p = num[i]; }
    		if (d[i] && now < i) { now = maxv; cho[p] = true; }
    	}
    	for (int i = 1;i <= m;i++) if (!cho[i]) ans[++ans[0]] = i;
    	printf("%d",ans[0]);
    	for (int i = 1;i <= ans[0];i++) printf("%c%d",i ^ 1 ? ' ' : '
    ',ans[i]);
    	return 0;
    }
    
  • 相关阅读:
    挂载在snap的/dev/loop占用100%问题
    机器学习3- 一元线性回归+Python实现
    机器学习-2 模拟评估与选择
    机器学习-1 绪论
    Java面试系列第4篇-HashMap相关面试题
    Java面试系列第3篇-类的加载及Java对象的创建
    Java面试系列第2篇-Object类中的方法
    Java面试系列第1篇-基本类型与引用类型
    第3篇-如何编写一个面试时能拿的出手的开源项目?
    第2篇-如何编写一个面试时能拿的出手的开源项目?
  • 原文地址:https://www.cnblogs.com/lrj124/p/14345162.html
Copyright © 2011-2022 走看看