标签:
/* **********************************************
CodeForces 607A
Author:herongwei
Created Time: 2016/5/31 13:00:00
File Name : main.cpp
一个线段上有n个灯塔,每个灯塔有两个属性
(位置和破坏距离)
现在一次性从右到左开启所有灯塔,每个灯塔开启后
只有该灯塔未被破坏时会破坏左边距离范围内所有灯塔,
问现在在最右边放置一个灯塔(位置和距离随意),所能破坏的最小灯塔数目
[solve]
c[i]表示第i个激活时,不考虑i右边的,有几个灯台能保留。
对第i个灯塔,找到它激活时,左边第一个能存活的塔j,
c[i] =c[j] + 1,没有能存活的则c[i] = 1
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
*********************************************** */
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int > pii;
const int maxn = 1e5+10;
int b[maxn],c[maxn];
int n,m;
pii st[maxn];
int main()
{
//freopen("1.txt","r",stdin);
while(~scanf("%d",&n))
{
memset(st,0,sizeof(st));
for(int i=0; i<n; ++i)
{
scanf("%d %d",&st[i].first,&st[i].second);
}
sort(st,st+n);
for(int i=0; i<n; ++i) b[i]=st[i].first;
c[0]=1;
int minn=1;
for(int i=1; i<n; ++i)
{
int k=st[i].first-st[i].second;
int ck=lower_bound(b,b+i+1,k)-b;
if(ck==0) c[i]=0;
c[i]=c[ck-1]+1;
minn=max(minn,c[i]);
}
printf("%d\n",n-minn);
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/u013050857/article/details/51553965