首页 > 编程语言 >算法战斗第二天C++2

算法战斗第二天C++2

时间:2023-12-13 22:11:06浏览次数:30  
标签:int 第二天 C++ ai 算法 score place participants Output

A. Next Round

"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.

A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.

Input:The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space.

The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).

Output:Output the number of participants who advance to the next round. Examples Input
8 5
10 9 8 7 7 7 5 5
Output
6
Input
4 2
0 0 0 0
Output
0
Note:In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.

In the second example nobody got a positive score.

输入第一个数字k为输入数字的个数,输入第二个数是比较值n,k中的数字有多少个比n大的输出,,,,,,,哒咩XXX这是不对的理解

请用成熟的英语语言理解这道题(裂开)第一段仔细品品,是应该与第k位的数值进行比较

我在博客里找到了一份绝美的答案,,,还是2017年的,我现在才开始认真学算法,,,然而她却在六年前就用我至今还不能轻松理解的语句写出答案。。。莫名其妙的嫉妒,又羡慕。。。

我的努力就像小狗屁。。。想哭,一个人在博学馆,大家都在努力备考四六级,备战考研,,,而我后知后觉又莫名其妙的在研究算法,呜呜呜

#include <iostream>

using namespace std;

int main(){
//	int i,n,k,j,a[51];
//	cin>>n>>k;
//	while(n>i) cin>>a[i++]; 
//	while (a[j]&&a[j]>=a[k-1])  ++j;
//    cout<<j;    
    int n,k,num=0,a[105];
	cin>>n>>k;
	for(int i=0;i<n;++i)cin>>a[i];
	for(int i=0;i<n;++i)
	    if(a[i]!=0 && a[i]>=a[k-1])num++;
	cout<<num<<endl;
	
    return 0;
}

 注释的是另一个方法不过调试没通过,,,emo了,回寝室充电去了,嘤嘤嘤。

 

 

 

 

标签:int,第二天,C++,ai,算法,score,place,participants,Output
From: https://www.cnblogs.com/AlbertKs220111/p/17899839.html

相关文章

  • 算法期末复习指北
    目录叠甲声明复习思路模板刷题复习重点基础考点复习选择题前置基础排序与堆动态规划DP贪心图论计算几何FFT字符串其它技巧正式考试一些想法注意事项最后叠甲声明这是一份并不算详细的算法复习指北,不包含算法详细讲解(想看详细讲解的去翻PPT或者找网上博客或者找oi-wiki),也不包含......
  • 代码随想录算法训练营第一天|704.二分查找、27.移除元素
    LeetCode704二分查找题目链接704.二分查找二分法确定区间(循环不变量):对于有序数组,定义循环区间二分查找元素 LeetCode27.移除元素题目链接:27.移除元素快慢指针,快指针查,慢指针存 ......
  • 基于WTMM算法的图像多重分形谱计算matlab仿真
    1.算法运行效果图预览 2.算法运行软件版本matlab2022a 3.算法理论概述       基于WTMM算法的图像多重分形谱计算是一种利用小波变换模极大值(WTMM)方法,对图像进行多重分形分析的方法。下面将详细介绍这种方法的原理和数学公式。 3.1、WTMM算法概述   ......
  • 代码随想录算法训练营第一天 | 数组理论基础,704. 二分查找,27. 移除元素
    一、数组理论基础学习前:1.数组定义一些在内存上连续存储的相同数据类型的数据的集合2.数组特征便于查询数组元素,不便于增删数据元素学习后:对于Java,二维数组不一定在内存上连续。如int[i][j],唯一确定的是int[i][]在内存上连续二、704.二分查找LeetCode704.二分查找......
  • SM4算法学习
    简介SM4算法是我国商用密码标准,其前身是SMS4算法。SM4算法是一个分组加密算法,分组长度和密钥长度均128bit。SM4算法使用32轮的非线性迭代结构。SM4在最后一轮非线性迭代之后加上了一个反序变换,因此SM4中只要解密密钥是加密密钥的逆序,它的解密算法与加密算法就可以保持一致。SM4......
  • 算法战斗第二天C++1
    A.TeamOnedaythreebestfriendsPetya,VasyaandTonyadecidedtoformateamandtakepartinprogrammingcontests.Participantsareusuallyofferedseveralproblemsduringprogrammingcontests.Longbeforethestartthefriendsdecidedthattheywi......
  • 代码随想录算法训练营第一天| LeetCode704 二分查找、27移除元素
     Leetcode704:二分查找今日学习的文章链接:代码随想录(programmercarl.com) 题目链接:704.二分查找-力扣(LeetCode)●  自己看到题目的第一想法这题我会,但是还没明白卡尔说的循环不变量是什么意思。我的固定思路就是,target比中间值大,左指针右移到mid+1;target比中间值......
  • 百度 推荐 投的cpp开发 不知道怎么给的推荐算法的岗位
    判断(){}是否合法?多线程通信方式手段?成员函数模板 类模板智能指针底层原理为什么引入linux文本定位到最后一行vi进入之后:$定位到最后一行  一、使用cat、tail、head组合1、查看最后100行的数据 catfilename|tail-n1002、查看100到300行的数据 cat......
  • C++ 析构函数 virtual 虚析构
    结论:当父类存在virtual函数时,则需要实现虚析构函数。直接上代码:#include<iostream>#include<memory>classAAA{public:AAA(){printf("AAA构造...\n");}//virtual~AAA(){printf("AAA析构...\n");}virtualvoidSayOk()=0;};cl......
  • 算法学习Day1,二分查找,移除元素
    Day1二分查找,移除元素ByHQWQF2023/12/13笔记704.二分查找给定一个n个元素有序的(升序)整型数组nums和一个目标值target,写一个函数搜索nums中的target,如果目标值存在返回下标,否则返回-1。解法:使用二分查找来在一个有序的数组中找到指定元素的下标。根据数据边界......