当前位置:网站首页>倒计数(来源:Google Kickstart2020 Round C Problem A)(DAY 88)
倒计数(来源:Google Kickstart2020 Round C Problem A)(DAY 88)
2022-07-30 05:26:00 【张学恒】
1:题目
艾弗里有一个由 N 个正整数构成的数组。
数组中的第 i 个整数是 Ai。
如果一个连续的子数组的长度为 m,并且按顺序包含整数 m,m−1,m−2,…,2,1,则称它为 m 倒计数。
例如,[3,2,1] 是 3 倒计数。
请帮助艾弗里计算她的数组中有多少个 K 倒计数。
输入格式
第一行包含整数 T,表示共有 T 组测试数据。
对于每组数据,第一行包含两个整数 N 和 K。
第二行包含 N 个整数,其中第 i 个表示 Ai。
输出格式
每组数据输出一个结果,每个结果占一行。
结果表示为 Case #x: y,其中 x 为组别编号(从 1 开始),y 为 K 倒计数的数量。
数据范围
1≤T≤100,
2≤K≤N,
1≤Ai≤2×105,
2≤N≤2×105
输入样例:
3
12 3
1 2 3 7 9 3 2 1 8 3 2 1
4 2
101 100 99 98
9 6
100 7 6 5 4 3 2 1 100
输出样例:
Case #1: 2
Case #2: 0
Case #3: 1
样例解释
在示例 1 中,有两个 3 倒计数,如下:
1 2 3 7 9 3 2 1 8 3 2 1
1 2 3 7 9 3 2 1 8 3 2 1
在示例 2 中,没有 2 倒计数。
在示例 3 中,有一个 6 倒计数,如下:
100 7 6 5 4 3 2 1 100
难度:简单
时/空限制:1s / 64MB
总通过数:845
总尝试数:1911
来源:Google Kickstart2020 Round C Problem A
算法标签
2:代码实现
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 200010;
int n, m;
int q[N];
int main()
{
int T;
scanf("%d", &T);
for (int cases = 1; cases <= T; cases ++ )
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++ ) scanf("%d", &q[i]);
int res = 0;
for (int i = n; i; i -- )
{
if (q[i] != 1) continue;
int j = i - 1;
while (j && q[j] == q[j + 1] + 1) j -- ;
if (i - j >= m) res ++ ;
i = j + 1;
}
printf("Case #%d: %d\n", cases, res);
}
return 0;
}
边栏推荐
- 分布式事务之 LCN框架的原理和使用(二)
- 工作效率-十五分钟让你快速学习Markdown语法到精通排版实践备忘
- 力扣541-反转字符串2——双指针法
- 力扣344-反转字符串——双指针法
- Codeforces Round #809 (Div. 2) A~D
- mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
- Summary of skills in using ms project2010 project management software
- C language implements highly secure game archives and reads files
- 力扣1047-删除字符串中的所有相邻重复项——栈
- 即刻报名|如何降低云上数据分析成本?
猜你喜欢

MySQL基础(DDL、DML、DQL)

MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)

给小白的 PostgreSQL 容器化部署教程(上)

Hexagon_V65_Programmers_Reference_Manual (12)

The Golden Circle Rule: Deep Thinking Methods for Successful People

How MySQL to prepare SQL pretreatment (solve the query IN SQL pretreatment can only query out the problem of a record)

mysql 中 in 的用法

从想当亿万富翁到职场、创业、爱情、抑郁、学医学武,我的程序人生

并发编程复习

ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序
随机推荐
go language study notes 4
JVM 垃圾回收 超详细学习笔记(二)
IIS网站出现401未授权访问
I went to meet some successful people worth tens of millions on May 1st, and I have some new ideas and inspirations
并发编程复习
MySQL(3)
MySQL索引从入门到深入学习
RadonDB PostgreSQL on K8s 2.1.0 发布!
Us to raise interest rates by 75 basis points in "technical recession"?Encryption market is recovering
DLL description (1)
无代码开发平台重新申请入门教程
期末作业C#实现学生宿舍管理系统
It's time to have to learn English, give yourself multiple paths
go language study notes 3
"Hou Lang" programmer version, a speech dedicated to a new generation of programmers, He Bing's "Hou Lang" speech imitation show
MySQL(4)
程序员赚钱实操,手把手教你做付费课程,自媒体,付费文章及付费技术课赚钱
视野 | KeyDB:为 Web 应用而生的高性能 Redis 分支
为Bitbucket 和 Sourcetree 设置SSL认证
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决