C. Chain Reaction
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n beacons located at distinct positions on a number line. The i-th
beacon has position ai and
power level bi.
When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive.
The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.

Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note
that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 100 000)
— the initial number of beacons.

The i-th of next n lines
contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) —
the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj if i ≠ j.

Output

Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.

Sample test(s)
input
  1. 4
  2. 1 9
  3. 3 1
  4. 6 1
  5. 7 4
output
  1. 1
input
  1. 7
  2. 1 1
  3. 2 1
  4. 3 1
  5. 4 1
  6. 5 1
  7. 6 1
  8. 7 1
output
  1. 3
Note

For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with
power level 2.

For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position1337 with
power level 42.

题目链接:点击打开链接

给出n个点的坐标以及照耀范围, 现要在最右边放置一个灯塔, 位置和照耀范围随意, 问最少有几个灯塔能够被摧毁.

dp数组记录第i个灯塔存在时照亮的数量, 求出每一个灯塔摧毁范围同一时候更新dp和记录最大的dp, 范围大于0则等于那个点照亮数量围, 且自

己伤害范围不为0时, 再把自己算进去.

AC代码:

  1. #include "iostream"
  2. #include "cstdio"
  3. #include "cstring"
  4. #include "algorithm"
  5. #include "queue"
  6. #include "stack"
  7. #include "cmath"
  8. #include "utility"
  9. #include "map"
  10. #include "set"
  11. #include "vector"
  12. #include "list"
  13. #include "string"
  14. #include "cstdlib"
  15. using namespace std;
  16. typedef long long ll;
  17. const int MOD = 1e9 + 7;
  18. const int INF = 0x3f3f3f3f;
  19. const int MAXN = 1e6 + 6;
  20. int n, dp[MAXN], magic[MAXN], ans;
  21. int main(int argc, char const *argv[])
  22. {
  23. scanf("%d", &n);
  24. for(int i = 0; i < n; ++i) {
  25. int x, y;
  26. scanf("%d%d", &x, &y);
  27. magic[x] = y;
  28. }
  29. for(int i = 0; i <= 1e6; ++i) {
  30. int x = i - magic[i] - 1;
  31. if(x < 0) dp[i] = 0;
  32. else dp[i] = dp[x];
  33. if(magic[i]) dp[i]++;
  34. if(dp[i] > ans) ans = dp[i];
  35. }
  36. printf("%d\n", n - ans);
  37. return 0;
  38. }

Codeforces Round #336 (Div. 2) 608C Chain Reaction(dp)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #336 (Div. 1) A - Chain Reaction

    Chain Reaction 题意:有n(1 ≤ n ≤ 100 000) 个灯泡,每个灯泡有一个位置a以及向左照亮的范围b (0 <= a <= 1e6 ,1<= b <= ...

  4. 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 ...

  5. Codeforces Round #336 (Div. 2) D. Zuma 区间dp

    D. Zuma   Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gems ...

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

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

  7. 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 ...

  8. Codeforces Round #336 (Div. 2)

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

  9. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

随机推荐

  1. (转)Hibernate框架基础——映射集合属性

    http://blog.csdn.net/yerenyuan_pku/article/details/52745486 集合映射 集合属性大致有两种: 单纯的集合属性,如像List.Set或数组等集合 ...

  2. CodeFrist基础_Fluent Api

    一丶首先新建两个实体类 public class Student { public int StudentKey { get; set; } public string StudentName { g ...

  3. css3属性之-webkit-margin-before

    当没有对浏览器进行css边距初始化时,在web-kit浏览器上会出现下面的浏览器默认边距设置: ul, menu, dir { display: block; list-style-type: dis ...

  4. javaScript--进阶1--数据类型、操作符

    一.JS基础知识背景 1.1 弱类型脚本语言 脚本语言是:弥补编译语言的不足而存在的,作为补充语言,不用编译,解析一行执行一行. 弱类型语言:简单理解定义一个变量,可以有多种数据类型.(var tem ...

  5. Python关于导入模块的一些感想:

    写项目的时候,碰到这种情况 程序业务为core,里面有两个目录,core1 和core2  core1中有三个模块,business  main   main1 程序入口为bin目录下的project ...

  6. mysql的密码管理、mysql初始密码查找、密码修改、mysql登录

    1.查询mysql的初始密码: 初始密码密码是随机产生的,每台机器产生的都不一样的 grep 'temporary password' /var/log/mysqld.log 或者 cat /var/ ...

  7. 【tips】自动化测试工具 - selenium和phantomJS

    ### 目录清单 selenium和phantomjs概述 selenium常用API 案例操作:模拟登陆csdn 1. selenium和phantomJS是什么东西 selenium是一套web网 ...

  8. ubuntu_linux自动补全出现问题

    问题:输入: cd p,使用Tab补全,期望进入pub_work目录,虽然自动补全,成功进入目录:却给我打印一连串的字符,纠结: fly@Flyme:~$ cd p+ local cur prev w ...

  9. 【14】AngularJS 表单

    AngularJS 表单 AngularJS 表单是输入控件的集合. HTML 控件 以下 HTML input 元素被称为 HTML 控件: input 元素 select 元素 button 元素 ...

  10. 2018.5.7每天一题面试题----final, finally, finalize 的区别

    1.final修饰符(关键字).被final修饰的类,就意味着不能再派生出新的子类,不能作为父类而被子类继承. 因此一个类不能既被abstract声明,又被final声明.将变量或方法声明为final ...