【CEOI2010】【BZOJ2013】A huge tower

Description

有N(2<=N<=620000)快砖,要搭一个N层的塔,要求:如果砖A在砖B上面,那么A不能比B的长度+D要长。问有几种方法,输出 答案 mod 1000000009的值
Input

第一行: N,D 第二行: N个数,表示每块砖的长度。
Output

方案数。输出要mod1000000009
Sample Input

4 1

1 2 3 100

Sample Output

4
HINT

Source

排序然后二分一下就好了
4352是双倍经验

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAXN 700010
#define GET (ch>='0'&&ch<='9')
#define P 1000000009
#define LL long long
using namespace std;
int n,d;
int a[MAXN];
LL ans=1;
void in(int &x)
{
    char ch=getchar();x=0;
    while (!GET)    ch=getchar();
    while (GET) x=x*10+ch-'0',ch=getchar();
}
int main()
{
    in(n);in(d);int id;
    for (int i=1;i<=n;i++)  in(a[i]);
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++)  id=lower_bound(a+1,a+i,a[i]-d)-a,ans=ans*(i-id+1)%P;
    printf("%lld\n",ans);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值