Chain Reaction

题意:有n(1 ≤ n ≤ 100 000) 个灯泡,每个灯泡有一个位置a以及向左照亮的范围b (0 <= a <= 1e6 ,1<= b <= 1e6);(题目是按照灯泡位置递增的顺序输入的)每个灯泡的毁坏范围就是灯泡的照亮范围(包括左边界,但是自己不会毁坏)。要你在所有灯泡的右边(不能有灯泡的位置相同)任意位置设置一个向左照亮范围任意的灯泡,使得先开设置的灯泡再从右往左开启题给的灯泡时毁坏的灯泡数最少。很绕,但是题目真的很好~~~

思路:dp+递推
pre[i]:位置为i时最多能保留的灯泡数;当位置没有灯泡时,设置照亮距离为1的”灯泡”(其实就是为设置的灯泡dp出最优的覆盖的左边界),递推到右边界,同时记录下所有位置的最大保留的灯泡数ans即可;(一般1e7完全可以在1s内A的,1e8要是系数小点也是有可能的)

//Accepted    61 ms   7836 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (n);i++)
const int MAXN = 1e6 + ;
int scope[MAXN],pre[MAXN];
int main()
{
int n,a,r,i,ans = ;
cin>>n;
rep(i,n){
scanf("%d%d",&a,&r);
scope[a] = r;
}
rep(i,MAXN){
int p = i - scope[i] - ;//看似范围时1,其实递推出了设置灯泡的左边界~
if(p < ) pre[i] = ;//不能直接max(p,0)注意a ?= 0
else pre[i] = pre[p];
if(scope[i]) pre[i]++;
ans = max(ans,pre[i]);
}
cout<<n - ans;
}

Codeforces Round #336 (Div. 1) A - Chain Reaction的更多相关文章

  1. Codeforces Round #336 (Div. 2) C. Chain Reaction set维护dp

    C. Chain Reaction 题目连接: http://www.codeforces.com/contest/608/problem/C Description There are n beac ...

  2. Codeforces Round #336 (Div. 2)C. Chain Reaction DP

    C. Chain Reaction   There are n beacons located at distinct positions on a number line. The i-th bea ...

  3. Codeforces Round #336 (Div. 2) 608C Chain Reaction(dp)

    C. Chain Reaction time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Codeforces Round #336 (Div. 2) D. Zuma

    Codeforces Round #336 (Div. 2) D. Zuma 题意:输入一个字符串:每次消去一个回文串,问最少消去的次数为多少? 思路:一般对于可以从中间操作的,一般看成是从头开始(因 ...

  5. Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】

    A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  6. Codeforces Round #336 (Div. 2)

    水 A - Saitama Destroys Hotel 简单的模拟,小贪心.其实只要求max (ans, t + f); #include <bits/stdc++.h> using n ...

  7. Codeforces Round #336 (Div. 2)B 暴力 C dp D 区间dp

    B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索

    D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...

  9. Codeforces Round #336 (Div. 2)B. Hamming Distance Sum 前缀和

    B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos need ...

随机推荐

  1. java 5 线程池

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Thr ...

  2. 为 vsftpd 启动 vsftpd:500 OOPS: bad bool value in config file for: pasv_enable

    每行的值都不要有空格,否则启动时会出现错误,举个例子,假如我在listen=YES后多了个空格,那我启动时就出现.. 为 vsftpd 启动 vsftpd:500 OOPS: bad bool val ...

  3. Using Sessions and Session Persistence---reference

    Using Sessions and Session Persistence The following sections describe how to set up and use session ...

  4. JSTL-core核心代码标签库中的if,set,out等的功能

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  5. ALTER---为已创建的表添加默认值

    alter table table_name modify column_name default default_value; 例: alter table userinfo modify emai ...

  6. centos6 install mplayer(multimedia)

    step_1 http://wiki.centos.org/AdditionalResources/Repositories/RPMForge step_2 http://wiki.centos.or ...

  7. EF6调用存储过程,返回多个结果集处理

    链接:http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram 案例: ...

  8. redis 在windows上运行

    参考自:https://github.com/ServiceStack/redis-windows 1.用vagrant 运行redis的最后版本 1.1在windows上安装vagrant http ...

  9. tomcat优化系列:修改运行内存

    1.对于安装版的TOMCAT: 进入TOMCAT的安装目录下的bin目录,双击tomcat6w.exe.点击Java选项卡,可设置初始化内存,最大内存,线程的内存大小. 初始化内存:如果机器的内存足够 ...

  10. android软件开发之webView.addJavascriptInterface循环渐进【二】

    本篇文章由:http://www.sollyu.com/android-software-development-webview-addjavascriptinterface-cycle-of-gra ...