CodeForces 607A (二分)

 /* **********************************************
   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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值