Codeforces Round #336 (Div. 2) 608C Chain Reaction(dp)
来源:互联网 发布:sql 保留小数位数 编辑:程序博客网 时间:2024/04/29 03:58
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.
41 93 16 17 4
1
71 12 13 14 15 16 17 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 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代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"#include "queue"#include "stack"#include "cmath"#include "utility"#include "map"#include "set"#include "vector"#include "list"#include "string"#include "cstdlib"using namespace std;typedef long long ll;const int MOD = 1e9 + 7;const int INF = 0x3f3f3f3f;const int MAXN = 1e6 + 6;int n, dp[MAXN], magic[MAXN], ans;int main(int argc, char const *argv[]){scanf("%d", &n);for(int i = 0; i < n; ++i) {int x, y;scanf("%d%d", &x, &y);magic[x] = y;}for(int i = 0; i <= 1e6; ++i) {int x = i - magic[i] - 1;if(x < 0) dp[i] = 0;else dp[i] = dp[x];if(magic[i]) dp[i]++;if(dp[i] > ans) ans = dp[i];}printf("%d\n", n - ans);return 0;}
- Codeforces Round #336 (Div. 2) 608C Chain Reaction(dp)
- Codeforces Round #336 (Div. 2) C. Chain Reaction
- Codeforces Round #336 (Div. 2)C. Chain Reaction
- Codeforces Round #336 (Div. 2)-C. Chain Reaction
- Codeforces Round #336 (Div. 2)-C Chain Reaction(二分+DP)
- Codeforces Round #336 (Div. 1)A. Chain Reaction(DP)
- Codeforces Round #336 (Div. 2) 608C Chain Reactio DP
- Codeforces Round #336 (Div. 1) 607A Chain Reaction 简单dp
- Codeforces Round #336 (Div. 1) A. Chain Reaction DP+(可选二分)
- Codeforces Round #336 (Div. 1) A - Chain Reaction
- 【Codeforces Round 336 (Div 2) C】【贪心 DP思维】Chain Reaction 每个灯塔位置为a[]破坏b[]范围所有灯塔 设置一个灯塔使得最多灯塔被保留
- 续Codeforces 608 C Chain Reaction
- 【33.33%】【codeforces 608C】Chain Reaction
- 【DP】Codeforces Round #336 (Div. 2) C
- Codeforces 607A Chain Reaction 【二分 + dp】
- CodeForces 607 A. Chain Reaction(dp)
- [CodeForces 607A]Chain Reaction[DP]
- Codeforces 607A Chain Reaction (dp+二分)
- 关于数据库的一些问题,同时给出了一些答案
- Xcode - Error creating LLDB target
- 使用webhdfs
- Android中如何关闭所有的Activity
- 聚类和判别分析小论文
- Codeforces Round #336 (Div. 2) 608C Chain Reaction(dp)
- 【hadoop】ssh localhost 免密码登陆(图解)
- Javascript DOM 编程艺术(second edition) 读书笔记(3)
- 我的第一个docker镜像
- hdu-
- Android选择头像(从相机-相册-截图获取),以及闪退的解决
- hihocoder 1107 : Shortest Proper Prefix
- OpenCV 学习笔记
- 欢迎阅读我的博客