当前位置:网站首页>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;
}
边栏推荐
- 5、 MFC view windows and documents
- 185. 部门工资前三高的所有员工(必会)
- 如何使用DevExpress WPF在WinUI中创建第一个MVVM应用程序?
- Analysis of [paper] pointlanenet papers
- Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
- Arduino UNO +74hc164 water lamp example
- Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
- 如何白嫖最新版BurpSuite Pro
- 2513: 小勇学分数(公约数问题)
- Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
猜你喜欢

Play a parallel multithreaded mcu-mc3172

After two years of graduation, I switched to software testing and got 12k+, and my dream of not taking the postgraduate entrance examination with a monthly salary of more than 10000 was realized

阿里云解决方案架构师张平:云原生数字化安全生产的体系建设

Cuteone: a onedrive multi network disk mounting program / with member / synchronization and other functions

OpenTelemetry 在服务网格架构下的最佳实践

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

Portraiture5全新升级版磨皮滤镜插件神器

setTimeout第一个参数应该注意的地方

小玩一个并行多线程MCU—MC3172
![Analysis of [paper] pointlanenet papers](/img/f6/8001be4f90fe15100e0295de02491f.png)
Analysis of [paper] pointlanenet papers
随机推荐
红宝书第四版的一个错误?
Integrated water conservancy video monitoring station telemetry terminal video image water level water quality water quantity flow velocity monitoring
Naive Bayes -- Document Classification
确定了,2022下半年软考报名8月开始
小玩一个并行多线程MCU—MC3172
ArduinoUNO驱动RGB模块全彩效果示例
机器学习【Matplotlib】
185. 部门工资前三高的所有员工(必会)
The most complete basic knowledge of software testing in the whole network (a must for beginners)
调用JShaman的Web API接口,实现JS代码加密。
[simple question of stack and queue] leetcode 232. realize queue with stack, 225. realize stack with queue
单例模式(双检锁)
力扣(LeetCode)207. 课程表(2022.07.26)
HCIP第十四天笔记
八皇后编程实现
day6
Kubernetes dashboard deployment application and access
一个测试类了解BeanUtils.copyProperties
阿里云解决方案架构师张平:云原生数字化安全生产的体系建设
数模1232