我是靠谱客的博主 长情大山,这篇文章主要介绍【Codeforces 158A】Next Round,现在分享给大家,希望可以做个参考。

【链接】 我是链接,点我呀:)
【题意】


让你找到排名的前k名,并列的话,如果分数大于0那么就算晋级
问你最后有多少人可以晋级.

【题解】


按照题意模拟就好,
先按照a[max] = a[k]的规则找到下标的最大值max
然后依据a[max]==0的规则,一直减小这个max.
直到max变成0为止。
最后输出max就好了

【代码】

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.Scanner; public class Main { public static int N = 50; public static int n,k; public static int a[]; public static void main(String[] args) { Scanner in = new Scanner(System.in); a = new int[N+10]; n = in.nextInt();k = in.nextInt(); for (int i = 1;i <= n;i++) a[i]= in.nextInt(); int ma = k; for (int i = k+1;i <= n;i++) if (a[i]==a[k]) { ma = i; } while (a[ma]==0 && ma>=1) ma--; System.out.println(ma); } }

转载于:https://www.cnblogs.com/AWCXV/p/10330527.html

最后

以上就是长情大山最近收集整理的关于【Codeforces 158A】Next Round的全部内容,更多相关【Codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部