题解 | #签到题I#

签到题I

https://ac.nowcoder.com/acm/problem/25519

签到题I题解

实现思路

这个其实我们可以直接使用求一个数组里面第kk大数的这个操作来实现

代码实现

/*
 * @Description: 电影和人生不一样,电影太仁慈了,人生太辛苦了
 * @CSDN: https://blog.csdn.net/godhandsjoker?spm=1000.2115.3001.5343
 * @Github: https://github.com/godhandsjoker
 * @QQ: 3124406837
 * @Author: godhands
 * @LastEditTime: 2022-04-28 10:58:27
 */
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &it : a) cin >> it;
    nth_element(a.begin(), a.begin() + (k - 1), a.end());
    cout << a[k - 1] << "\n";
}
signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    solve();
    return 0;
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务