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. [2014.5.22][UBUNTU]Ubuntu与Windows系统时间不同步的问题

    安装Ubuntu+Windows双系统时会遇到Windows和Ubuntu系统时间不同步的问题,这是由于Windows系统默认读取主板bios等硬件系统时间作为OS的当地时间;而MAc,Linux类的 ...

  2. PHP class_exists 检查类是否已定义

    (PHP 4, PHP 5)  class_exists — 检查类是否已定义 bool class_exists ( string $class_name [, bool $autoload ] ) ...

  3. NSMakeRange基础函数应用

    NSRange NSMakeRange ( NSUInteger loc, NSUInteger len ); 这是官方得接口描述.loc 为location缩写,len 表示长度.作用:在loc指定 ...

  4. android94 样式和主题

    style.xml <resources xmlns:android="http://schemas.android.com/apk/res/android"> < ...

  5. MySQL【第二篇】基本命令

    一.连接MySQL 登录 mysql 有两种方式: 远程主机:mysql -h主机地址 -u用户名 -p密码 -P端口号 本机:mysql -h主机地址 -u用户名 -p密码 -P端口号 如果端口号是 ...

  6. 解锁Dagger2使用姿势(二) 之带你理解@Scope

    关于Dagger2使用的基础如果你还不了解,可以参考我的上一篇文章解锁Dagger2使用姿势(一),这有助于你理解本篇文章. OK,我们在上篇文章介绍另外Dagger2使用过程中四个基本的注解,分别是 ...

  7. 在MyEclipse中如何去掉JS或jsp语法错误提示!

    在MyEclipse中如何去掉JS或jsp语法错误提示! 关于在 MyEclipse 上 WEB 工程里面的 JS/JSP 经常会有语法错误提示,这是由于 MyEclipse 对其语法要求相当严格所造 ...

  8. arcgis 获得路径和环境变量信息

    import arcpy import sysimport osimport string reload(sys) sys.setdefaultencoding("utf8")sc ...

  9. UITableViewCell的选中时的颜色及tableViewCell的selecte与deselecte

    1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = ...

  10. youku的js脚本的工具函数和初始化方法

    定义日志输出函数 (function(){ if(window['console']){ return; } window['console'] = { log: function(){} ,clea ...