Codeforces Round #336 (Div. 2)C. Chain Reaction DP
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.
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.
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
4
1 9
3 1
6 1
7 4
1
7
1 1
2 1
3 1
4 1
5 1
6 1
7 1
3
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 9with 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个灯,每个灯在ai有一个威力值bi, 开启它,使得左边与其距离小于等于 bi 的会损坏
现在给你一个机会 可以在最右端 放一个 任意位置任意威力值的灯,并且从最右端的灯开始开启 问你最少的损坏的灯个数是多少
题解:设DP[i] 表示从1到i的这段距离内 不会损坏的 灯个数是多少
因为我们是开启灯 灯就不会损坏
dp[i] = dp[a[cnt]-b[cnt]-1] + 1; (1<=cnt<=n);
//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; struct ss{
int p,s,S;
}a[N];
int n,b[N],H[N],t[M],sum[N],dp[M+];
int cmp(ss s1,ss s2) {return s1.p<s2.p;} int main () { scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%d%d",&a[i].p,&a[i].s);
a[i].S=a[i].p-a[i].s-;
}
int cnt=; int tmp;
sort(a+,a+n+,cmp);
int ans=,L=;
int cc=;
for(int i=;i<=M;i++) {
if(i==a[cc].p) {
if(a[cc].S>=) {
dp[i] = dp[a[cc].S] +;
}
else dp[i] = ;
cc++;
}
else dp[i] = dp[i-];
ans=max(dp[i],ans);
// cout<<dp[i]<<endl;
}
cout<<n-ans<<endl;
return ;
}
daima
Codeforces Round #336 (Div. 2)C. Chain Reaction DP的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #336 (Div. 1) A - Chain Reaction
Chain Reaction 题意:有n(1 ≤ n ≤ 100 000) 个灯泡,每个灯泡有一个位置a以及向左照亮的范围b (0 <= a <= 1e6 ,1<= b <= ...
- 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 ...
- 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 ...
- Codeforces Round #336 (Div. 2) D. Zuma
Codeforces Round #336 (Div. 2) D. Zuma 题意:输入一个字符串:每次消去一个回文串,问最少消去的次数为多少? 思路:一般对于可以从中间操作的,一般看成是从头开始(因 ...
- 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 ...
- Codeforces Round #336 (Div. 2)
水 A - Saitama Destroys Hotel 简单的模拟,小贪心.其实只要求max (ans, t + f); #include <bits/stdc++.h> using n ...
- Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...
随机推荐
- Swift 类构造器的使用
Swift 中构造器需要遵循的规则还是很多的, 总结一下, 有以下规则: 调用相关 指定构造器必须调用它直接父类的指定构造器方法. 便利构造器必须调用同一个类中定义的其它初始化方法. 便利构造器在最后 ...
- bootstrap bootstrapTable 分页 传值问题
bootstrapTable 分页传值 配置项:将原始的 limit: params.limit, //页面大小 page: params.offset, //页码 改成 limit: params ...
- IIS 8.5配置.net网站[花了半个多小时]
1.默认安装了IIS部分功能.参考http://www.cnblogs.com/xuanhun/p/4201645.html 2.运用程序连接池, 使用集成 模式 3.运用程序连接池,设置启用32位应 ...
- java提高篇-----详解java的四舍五入与保留位
转载:http://blog.csdn.net/chenssy/article/details/12719811 四舍五入是我们小学的数学问题,这个问题对于我们程序猿来说就类似于1到10的加减乘除那么 ...
- inout用法浅析
inout io_data; reg out_data; reg io_link; assign io_data=io_link? out_data:'bz; //当IO_data作为输入口使用时,一 ...
- UML 中的用例图解析以及starUML详细介绍
UML中的用例(Use Case)概念分析及StarUML实例 在UML 中use case 似 乎最簡單的,用例建模的最主要功能就是用来表达系统的功能性需求或行为,依我的理解用例建模可分为用例图和用 ...
- Protocol-SPI协议
说明.文章摘自:SPI协议及其工作原理浅析 http://bbs.chinaunix.net/thread-1916003-1-1.html 一.概述. SPI,Serial Peripheral I ...
- SqlHelper include Transaction
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- JQuery 对 Select option 的操作---转载
<select id="selectID" > <option value="1">1</option> <optio ...
- 20145103《java程序设计》第4周学习总结
20145103 <Java程序设计>第4周学习总结 教材学习内容总结 继承 继承共同行为 ·继承基本上就是避免多个类间重复定义共同行为. ·继承的三个好处:减少代码冗余:维护变得简单:扩 ...