当前位置:网站首页>Acwing 2074. Countdown simulation
Acwing 2074. Countdown simulation
2022-07-27 03:16:00 【Alkali!】
Title Description
https://www.acwing.com/problem/content/description/2076/
The general meaning of the title is T T T Group sequence , The sequence length of each group is different , The length will be given each time , Give a number at the same time K K K, Let you find out how many consecutive [ K , k − 1 , k − 2 , . . . , 1 ] [K,k-1,k-2,...,1] [K,k−1,k−2,...,1].
The title is not difficult. , Direct simulation is fine , Let's look at my code ideas .
Code
#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; // Record group number , from 1 Start
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) // Find a number in the sequence equal to k
{
if(n-i<k) break;// At this time, if the remaining sequence length is less than k, There is no need to look for it directly , There will be no more qualified
// Judge whether it is countdown
bool flag=true;
for(j=i;j<=i+k-1;j++)
if(num[j]!=k-(j-i))
{
flag=false;
break;
}
if(flag) // It's a countdown
{
count++;
i=i+k-1+1; // hold i Update to the next countdown
}
else // Not counting down
i=j; // hold i Update to the first non conformance
}
else
i++;
}
printf("Case #%d: %d\n",cnt++,count);
}
return 0;
}
边栏推荐
- 商城小程序项目完整源码(微信小程序)
- 正方形数组的数目(DAY 81)
- 水仙花数(DAY 78)
- [二分查找中等题] LeetCode 34. 在排序数组中查找元素的第一个和最后一个位置
- shell(38) : ssh端口转发
- {“errcode“:44001,“errmsg“:“empty media data, hint: [1655962096234893527769663], from ip: 222.72.xxx.
- SAFE-ARC/WARNER电源维修XENON氙灯电源维修分析
- 196. Delete duplicate email addresses
- 调用JShaman的Web API接口,实现JS代码加密。
- 在线问题反馈模块实战(十五):实现在线更新反馈状态功能
猜你喜欢

次轮Okaleido Tiger即将登录Binance NFT,引发社区热议

Worthington木瓜蛋白酶解离系统解决方案

vector 转 svg 方法

Attention should be paid to the first parameter of setTimeout

毕业2年转行软件测试获得12K+,不考研月薪过万的梦想实现了

QT编译出来的exe以管理员权限启动

Best practices of opentelemetry in service grid architecture

How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?

使用 WebSocket 实现一个网页版的聊天室(摸鱼更隐蔽)

记录一次,php程序访问系统文件访问错误的问题
随机推荐
全网最全的软件测试基础知识整理(新手入门必学)
Common questions and answers of software testing interview (divergent thinking, interface, performance, concept,)
五、MFC视图窗口和文档
百度云人脸识别
Plato Farm全新玩法,套利ePLATO稳获超高收益
[binary search medium] leetcode 34. find the first and last positions of elements in the sorted array
力扣(LeetCode)207. 课程表(2022.07.26)
HCIP第十四天笔记
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
Ten thousand words long text, take you to understand the kubernetes network model
Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
[hash table] question collection
175. 组合两个表(非常简单)
正方形数组的数目(DAY 81)
Go to export excel form
Worthington过氧化物酶活性的6种测定方法
食物链(DAY 79)
2649: segment calculation
Compile and use protobuf Library in vs2019
[动态规划简单题] LeetCode 53. 最大子数组和