显然存在一个最优解满足所有青蛙在连续的一段, 每次由最左侧青蛙跳向下一格.

然后二分或者双指针即可求出答案.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+10;
int a[N], f[N]; int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m, d;
scanf("%d%d%d", &n, &m, &d),m+=2;
REP(i,1,m) scanf("%d", a+i);
REP(i,1,m) {
if (a[i]-a[1]<=d) f[i] = 1;
else {
int j = f[i-1];
while (a[i]-a[j]>d) ++j;
f[i] = j+1;
}
}
printf("%d\n", m-f[m]+1);
}
}

最新文章

  1. Specified key was too long; max key length is 767 bytes mysql
  2. Python_sklearn机器学习库学习笔记(一)_Feature Extraction and Preprocessing(特征提取与预处理)
  3. Android渗透测试Android渗透测试入门教程大学霸
  4. 三方框架之masonry
  5. telnet localhost 8089 ==》》命令使用
  6. jquery select操作和联动操作
  7. vi 编辑器初步
  8. 开通域名绑定DDNS
  9. Ansible Filter
  10. keepalived配置文件
  11. Linux SDK之uClinux、Broadcom、Atheros、Realtek、Ralink、Marvell、Intel
  12. find命令 参数
  13. Balanced Number 数位dp
  14. Apache SkyWalking的架构设计【译文】
  15. Scanner和BufferedReader的区别和用法
  16. Linux 配置TomCat 项目三大步骤
  17. python 去除不可见的控制字符
  18. 010. C++ 传值与传引用
  19. Appcompat实现Action Bar的兼容性处理
  20. Android 进阶12:进程通信之 Socket (顺便回顾 TCP UDP)

热门文章

  1. 用HQL自己写了个update!!!
  2. abstract Factory pattern
  3. 单调队列优化dp(捡垃圾的机器人)
  4. caps lock 映射成 esc,右Ctrl映射右移
  5. docker网络(3)
  6. c99数组稀疏初始化
  7. 给php安装openssl扩展
  8. Linux学习—rpm包管理
  9. 【Zookeeper】利用zookeeper搭建Hdoop HA高可用
  10. JAVA上传文件到数据库