牛客 158F 青蛙 (贪心)
2024-09-06 22:35:08
显然存在一个最优解满足所有青蛙在连续的一段, 每次由最左侧青蛙跳向下一格.
然后二分或者双指针即可求出答案.
#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);
}
}
最新文章
- Specified key was too long; max key length is 767 bytes mysql
- Python_sklearn机器学习库学习笔记(一)_Feature Extraction and Preprocessing(特征提取与预处理)
- Android渗透测试Android渗透测试入门教程大学霸
- 三方框架之masonry
- telnet localhost 8089 ==》》命令使用
- jquery select操作和联动操作
- vi 编辑器初步
- 开通域名绑定DDNS
- Ansible Filter
- keepalived配置文件
- Linux SDK之uClinux、Broadcom、Atheros、Realtek、Ralink、Marvell、Intel
- find命令 参数
- Balanced Number 数位dp
- Apache SkyWalking的架构设计【译文】
- Scanner和BufferedReader的区别和用法
- Linux 配置TomCat 项目三大步骤
- python 去除不可见的控制字符
- 010. C++ 传值与传引用
- Appcompat实现Action Bar的兼容性处理
- Android 进阶12:进程通信之 Socket (顺便回顾 TCP UDP)