轻重搭配|2019 蓝桥杯省赛 B 组模拟赛(一)第8题
轻重搭配|2019 蓝桥杯省赛 B 组模拟赛(一)第8题
利用贪心解决


#include<vector>
#include<iostream>
using namespace std;
vector<int > cp;
int n,ans = 0;
int main(){
    scanf("%d", &n);
    cp.resize(n);
    for(int i = 0; i < n; i++){
        cin>>cp[i];
    }
    sort(cp.begin(), cp.end());
    int pos = n/2,ans = n;
    for(int i = 0; i < n/2; i++){
        while(cp[i] * 2 > cp[pos] &&pos < n) pos++;
        if(pos >= n) break;
        ans --;
        pos ++;
    }
    cout<<ans;
    return 0;
}

相关文章:

  • 2022-12-23
  • 2022-01-19
  • 2021-11-20
  • 2021-04-09
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-09
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-09-09
相关资源
相似解决方案