当前位置:网站首页>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;
}
边栏推荐
- Rust web (I) -- self built TCP server
- How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?
- Favicon web page collection icon online production PHP website source code /ico image online generation / support multiple image format conversion
- Is the low commission account opening of Galaxy Securities Fund reliable, reliable and safe
- Quick sort
- [动态规划中等题] LeetCode 198. 打家劫舍 740. 删除并获得点数
- cocos小游戏实战-05-NPC与角色攻击逻辑
- 调用JShaman的Web API接口,实现JS代码加密。
- 数模1232
- 对象创建的流程分析
猜你喜欢

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community

Plato Farm全新玩法,套利ePLATO稳获超高收益

Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
![Analysis of [paper] pointlanenet papers](/img/f6/8001be4f90fe15100e0295de02491f.png)
Analysis of [paper] pointlanenet papers

制作ppt时间轴

批量复制宝贝上传提示乱码,如何解决?

小玩一个并行多线程MCU—MC3172

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community

万字长文,带你搞懂 Kubernetes 网络模型

ArduinoUNO驱动RGB模块全彩效果示例
随机推荐
Alibaba cloud technology expert Yang Zeqiang: Construction of observability on elastic computing cloud
Plato Farm全新玩法,套利ePLATO稳获超高收益
idea中常用的快捷键
localStorage与sessionStorage
Analysis of [paper] pointlanenet papers
[hash table] question collection
HCIP第十三天笔记
1.28亿美元!芬兰量子计算公司IQM获世界基金支持
毕业2年转行软件测试获得12K+,不考研月薪过万的梦想实现了
八皇后编程实现
批量复制宝贝上传提示乱码,如何解决?
对象创建的流程分析
Scheduling of processes
Worth more than 100 million! The 86 version of "red boy" refuses to be a Daocheng Xueba. He is already a doctor of the Chinese Academy of Sciences and has 52 companies under his name
ansible系列之:不收集主机信息 gather_facts: False
How to use devaxpress WPF to create the first MVVM application in winui?
LabVIEW中编程更改进程的优先级
Role of thread.sleep (0)
Kubernetes Dashboard 部署应用以及访问
Database read-write separation and database and table segmentation