zoukankan      html  css  js  c++  java
  • 【【henuacm2016级暑期训练】动态规划专题 F】Physics Practical

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

    给你n个数字 让你删掉最小的数字 使得: 剩余的数字中 "最大的数字"小于等于"最小的数字*2"

    【题解】

    把数据从小到大排序。 显然只有删掉最小的数字或者最大的数字才可能改变最大数字和最小数字的比例 那么我们枚举最后的结果产生的那一刻最小的数字是什么。 设为x 则在数组中找到最大的一个位置i且a[i]<=2*x 则我们只需要把比x小的数字删掉。比a[i]大的数字删掉就能造成这种局面了 即最大值和最小值满足题目的要求。 取操作次数的最小值就可以了。 (提交的时候注意要加读写文件

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1e5;
    
    int a[N+10],n;
    
    int main()
    {
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        ios::sync_with_stdio(0),cin.tie(0);
        cin >> n;
        for (int i = 1;i <= n;i++) cin >> a[i];
        sort(a+1,a+1+n);
        int ans = -1;
        for(int i = 1;i <= n;i++){
            int index = upper_bound(a+1,a+1+n,2*a[i])-a;
            index--;
            int cost = i-1 + n-index;
            if (ans==-1)
                ans = cost;
            else
                ans = min(ans,cost);
        }
        cout<<ans<<endl;
        return 0;
    }
    
    
  • 相关阅读:
    ubuntu 16.04 安装显卡驱动,再安装cuda
    8. golang 基本类型转换
    7.golang的字符串 string
    5. 变量定义
    4. 代码规范
    3.golang 的注释
    1.windows server 201x
    exec 命令
    powershell
    1.Dockerfile
  • 原文地址:https://www.cnblogs.com/AWCXV/p/9310044.html
Copyright © 2011-2022 走看看