首页 > 编程语言 >Problem P05. [算法课分治] 寻找第 k 个最大元素

Problem P05. [算法课分治] 寻找第 k 个最大元素

时间:2022-09-03 02:33:06浏览次数:72  
标签:sort arr int scanf 分治 P05 Problem include

image

sort进行排序,然后输出第k大的元素即可

#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>

using namespace std;

int n, k;
int arr[10005];

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++){
        scanf("%d", &arr[i]);
    }
    sort(arr, arr+n);
    printf("%d", arr[n-k]);
    return 0;
}

标签:sort,arr,int,scanf,分治,P05,Problem,include
From: https://www.cnblogs.com/understanding-friends/p/16651847.html

相关文章

  • CF1513 E Cost Equilibrium / F Swapping Problem
    E先做差,发现排列如果出现正负正负或负正负正就会挂,调整一下匹配即可使min变大同时如果正和负都>1,则不存在中间一段左右两段其他的,这样也会挂然后随便组合一下F手玩发......
  • Problem P01. [算法课分治] 最大二叉树
    需要注意的:scanf()的返回值是EOF,输入结束通过指针指向左右子树的二叉树构建#include<iostream>#include<bits/stdc++.h>#include<cstdio>usingnamespacestd;......
  • CF464E The Classic Problem
    传送门思路\(2^{100000}\)?别想了,普通高精度肯定不行但我们发现,求最短路的过程中,其实是用到了比较大小和加法操作细想比较大小的过程,当长度相同的数,我们会先略过前面......
  • MathProblem 76 Two bags and marble problem
    Youchooseoneoftwoidenticallookingbagsatrandom.Onebaghasthreeblackmarblesandonewhitemarble.Theotherhasthreewhitemarblesandoneblackm......
  • MathProblem 71 Nine pearls and a scale problem
    Youhaveninepearls,eightarerealandoneisfake.Alltherealonesweighthesameandthefakeweighslessthantherealones.Usingabalancescaletwice......
  • MathProblem 68 Four weights and a scale problem
    Usingabalancescaleandfourweightsyoumustbeabletobalanceanyintegerloadfrom\(1\)to\(40\).Howmuchshouldeachofthefourweightsweigh?Solut......
  • 树的难题 BJOI2017 点分治 单调队列
    P3714[BJOI2017]树的难题没时间码先口胡。明显有一个n^2的暴力。可以拿到20分。链的情况也非常容易一个简单的单调队列就可以解决当然可以暴力的采用线段树。这样......
  • 文献学习-Proofs for Satisfiability Problems
    ProofsforSatisfiabilityProblemsMarijnJ.H.HeuleandArminBiere1TheUniversityofTexasatAustin,UnitedStates2JohannesKeplerUniversity,Linz,Aus......
  • [洛谷P5787] 线段树时间分治
    题目大意给\(n\)个点\(m\)条边,在\(k\)时间内,第\(i\)条边只在\([l_i+1,r_i]\)的时间范围内存在。对于每个\(i\leqk\),输出\(i\)时刻这个图是否是二分图。题......
  • MathProblem 61 Coin toss problem #3
    Supposeyouhaveacoininwhichtheprobabilityofflippingaheadsis\(p\),where\(p\ge0.5\).Whatistheexpectednumberofflipsitwilltakeforthenu......