当前位置:网站首页>AcWing 2074. 倒计数 模拟
AcWing 2074. 倒计数 模拟
2022-07-27 00:52:00 【Alkali!】
题目描述
https://www.acwing.com/problem/content/description/2076/
题目大致意思是有 T T T组序列,每组序列长度不同,每次会给出长度,同时给出一个数 K K K,让你找出每个序列中有多少个连续的 [ K , k − 1 , k − 2 , . . . , 1 ] [K,k-1,k-2,...,1] [K,k−1,k−2,...,1]。
题目不难,直接模拟就行,下面看我代码思路。
代码
#include<iostream>
using namespace std;
const int N=2e5+10;
int num[N];
int t,n,k;
int main()
{
scanf("%d",&t);
int cnt=1; //记录组别编号,从1开始
while(t--)
{
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++) scanf("%d",&num[i]);
int count=0,i,j;
for(i=0;i<n;)
{
if(num[i]==k) //在序列中找到一个数等于k
{
if(n-i<k) break;//此时如果剩余的序列长度小于k,那直接不用再找了,不会再有符合条件的
//判断是不是倒计数
bool flag=true;
for(j=i;j<=i+k-1;j++)
if(num[j]!=k-(j-i))
{
flag=false;
break;
}
if(flag) //是倒计数
{
count++;
i=i+k-1+1; //把i更新到倒计数的下一个
}
else //不是倒计数
i=j; //把i更新到第一个不符合的情况
}
else
i++;
}
printf("Case #%d: %d\n",cnt++,count);
}
return 0;
}
边栏推荐
- Arduino UNO +74hc164 water lamp example
- typora详细教程
- [simple question of stack and queue] leetcode 232. realize queue with stack, 225. realize stack with queue
- 小玩一个并行多线程MCU—MC3172
- [SQL简单题] LeetCode 627. 变更性别
- Inftnews | ggac and China Aerospace ases exclusively produce "China 2065 Collection Edition"
- 在线问题反馈模块实战(十五):实现在线更新反馈状态功能
- 红宝书第四版的一个错误?
- Debezium series: the binlog file cannot be recovered after the record is hung from the library server, and the task is switched to the main library to ensure that the data is not lost
- Scheduling of processes
猜你喜欢

基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)

Arduinouno drive RGB module full color effect example
全网最全的软件测试基础知识整理(新手入门必学)

Favicon web page collection icon online production PHP website source code /ico image online generation / support multiple image format conversion

批量复制宝贝上传提示乱码,如何解决?
The most complete basic knowledge of software testing in the whole network (a must for beginners)

The EXE compiled by QT is started with administrator privileges

iNFTnews | “流量+体验”白衬e数字时装节引领数字时装新变迁

五、MFC视图窗口和文档
![[paper]PointLaneNet论文浅析](/img/f6/8001be4f90fe15100e0295de02491f.png)
[paper]PointLaneNet论文浅析
随机推荐
Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
Plato Farm全新玩法,套利ePLATO稳获超高收益
Marqueeview realizes sliding display effect
196. 删除重复的电子邮箱
185. 部门工资前三高的所有员工(必会)
iNFTnews | GGAC联合中国航天ASES 独家出品《中国2065典藏版》
Use of formdata
window对象的常见事件
Favicon网页收藏图标在线制作PHP网站源码/ICO图片在线生成/支持多种图片格式转换
Ten thousand words long text, take you to understand the kubernetes network model
Play a parallel multithreaded mcu-mc3172
单例模式(双检锁)
ZJCTF_login
机器学习【Matplotlib】
一道数学题,让芯片巨头亏了5亿美金!
数模1232
175. 组合两个表(非常简单)
在线问题反馈模块实战(十五):实现在线更新反馈状态功能
Boom 3D全新2022版音频增强应用程序App
Kubeadmin到底做了什么?