牛客 158F 青蛙 (贪心)
显然存在一个最优解满足所有青蛙在连续的一段, 每次由最左侧青蛙跳向下一格.
然后二分或者双指针即可求出答案.
#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);
}
}
牛客 158F 青蛙 (贪心)的更多相关文章
- 牛客练习赛24题解(搜索,DP)
A题,C题不讲,基础题(但是我要抨击一下这次比赛,卡cin,cout,卡的太狠了,根本就不让过的那种,QAQ) 链接:https://www.nowcoder.com/acm/contest/157/ ...
- 牛客网 桂林电子科技大学第三届ACM程序设计竞赛 C.二元-K个二元组最小值和最大-优先队列+贪心(思维)
链接:https://ac.nowcoder.com/acm/contest/558/C来源:牛客网 小猫在研究二元组. 小猫在研究最大值. 给定N个二元组(a1,b1),(a2,b2),…,(aN, ...
- [堆+贪心]牛客练习赛40-B
传送门:牛客练习赛40 题面: 小A手头有 n 份任务,他可以以任意顺序完成这些任务,只有完成当前的任务后,他才能做下一个任务 第 i 个任务需要花费 x_i 的时间,同时完成第 i 个任务的时间不 ...
- 牛客练习赛16 A 字典序最大的子序列【贪心】
链接:https://www.nowcoder.com/acm/contest/84/A 来源:牛客网 [出处]:http://codeforces.com/contest/196/problem/A ...
- 牛客网挑战赛24 青蛙(BFS)
链接:https://www.nowcoder.com/acm/contest/157/E来源:牛客网 有一只可爱的老青蛙,在路的另一端发现了一个黑的东西,想过去一探究竟.于是便开始踏上了旅途 一直这 ...
- 牛客网 江西财经大学第二届程序设计竞赛同步赛 D.绕圈游戏-(跳青蛙游戏)找数的所有因子就可以了
链接:https://ac.nowcoder.com/acm/contest/635/D来源:牛客网 D.绕圈游戏 433为了帮ddd提升智商,决定陪他van特殊的游戏.433给定一个带有n个点的环, ...
- 牛客网 小白赛4 A三角形【贪心】
[前驱]:在指定长度的棍子中找到能组成最大周长三角形的三根棍子 链接:https://www.nowcoder.com/acm/contest/134/A 来源:牛客网 题目描述 铁子从森林里收集了n ...
- 牛客多校2 D-money(dp记录/贪心)
D-money 链接:https://www.nowcoder.com/acm/contest/140/D来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K, ...
- 牛客练习赛51 **E-数列** (二分,贪心,构造)
牛客练习赛51 E-数列 链接:https://ac.nowcoder.com/acm/contest/1083/E来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 327 ...
随机推荐
- csp-s模拟80(b)
头一次中午考试,上来一看三个题目以为是三个板子,但一看数据范围就不对劲. T1: 考场上的想法是:找出循环节,对于数组一头一尾的不在循环节中的,维护出以某数结尾/开头的上升序列,对于中间的循环部分只取 ...
- springboot properties
Spring-boot中Conditional介绍 https://blog.csdn.net/tanga842428/article/details/78615070springBoot----@C ...
- 检查并解决CentOS 7 安装Tomcat是否成功
参考网址 https://blog.csdn.net/Blue_Sky_rain/article/details/91348791
- qt+opencv编译环境的配置
第一步:安装与配置Qt 从https://account.qt.io/downloads下载Qt,并注册账户.开始安装.首先下载qt-opensource-windows-x86-mingw482_o ...
- github上打开或下载过慢的问题解决
1.用站长工具查询github.com http://tool.chinaz.com/dns?type=1&host=github.com&ip= 2.找到“美国[海外]”项查到的ip ...
- linux下如何更新当前的容器镜像?
docker commit <container_id> <container_image_name>
- acl设置问题
在学习nfs服务配置的时候用到了acl规则(服务配置文件权限设置可写,但是由于客户端映射,不能写入,所以要设置系统权限),但是遇到了一个小小的问题:一.当使用-x选项取消规则的时候,再次查看权限后面仍 ...
- LC 980. Unique Paths III
On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square. There is e ...
- PHP格式化数字和SMARTY格式化数字的方法
PHP格式化: $num="3";$format="%06d"; //6是位数,这里有6位数,0是不足6位的补0$a=sprintf($format,$num ...
- react-native-picke Cannot read property '_init' of undefined
使用react-native-picker报以下错误: 查看了react-native-picke的issues: https://github.com/beefe/react-native-pick ...