Coder-Strike 2014 - Round 1 B. Network Configuration

题目的意思就是给每台电脑的最大传输速度,可以限制每台电脑的最大速度,然后选择k台电脑,使这k台电脑有相同的速度,且这个速度最大

典型的贪心算法,电脑的速度排个序,选择第k大速度即可

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,k;
    cin >>n >> k;
    vector<int> a(n);
    for(int i = 0 ; i < n ; ++ i) cin >> a[i];
    sort(a.begin(),a.end());
    cout<< a[n-k]<<endl;
}

 

posted @ 2014-04-19 12:32  OpenSoucre  阅读(150)  评论(0编辑  收藏  举报