zoukankan      html  css  js  c++  java
  • 【河南省多校脸萌第六场 A】分班级

    【链接】点击打开链接


    【题意】


    在这里写题意

    【题解】


    最大的给了最小的,实际上就对应了,最大值减1,最小值加1.
    那么二分最后班级人数最小的最大可能是几->temp1;
    二分最后班级人数最大的最小可能是几->temp2;
    对于二分的m;
    看看比它小的数字,ju都加上m-a[i];然后看看ju是不是小于等于k,根据这个改变二分的值
    最后输出max(temp2-temp1,0);(因为可能最后全都变成一样了)

    【错的次数】


    0

    【反思】


    在这了写反思

    【代码】

    /*
     
    */
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <set>
    #include <cstdlib>
    #include <cmath>
    #include <bitset>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb emplace_back
    #define fi first
    #define se second
    #define ld long double
    #define ms(x,y) memset(x,y,sizeof x)
    #define ri(x) scanf("%d",&x)
    #define rl(x) scanf("%lld",&x)
    #define rs(x) scanf("%s",x)
    #define rf(x) scnaf("%lf",&x)
    #define oi(x) printf("%d",x)
    #define ol(x) printf("%lld",x)
    #define oc putchar(' ')
    #define os(x) printf(x)
    #define all(x) x.begin(),x.end()
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0)
    #define sz(x) ((int) x.size())
    #define ld long double
     
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
     
    //mt19937 myrand(time(0));
    //int get_rand(int n){return myrand()%n + 1;}
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 50e4;
     
    int n,k,a[N+10];
     
    int main(){
        //Open();
        //Close();
        ri(n),ri(k);
        rep1(i,1,n) ri(a[i]);
        int l = 0,r = 1e9,temp1 = 0;
        while (l <= r){
            int m = (l+r)>>1;
            LL ju = 0;
            rep1(i,1,n)
                if (a[i] < m){
                    ju += m-a[i];
                }
            if (ju <= k){
                temp1 = m;
                l = m + 1;
            }else
                r = m - 1;
        }
     
        l = 0,r = 1e9;int temp2 = 0;
        while (l <= r){
            int m = (l+r)>>1;
            LL ju = 0;
            rep1(i,1,n)
                if (a[i]>m){
                    ju += a[i]-m;
                }
            if (ju <=k ){
                temp2 = m;
                r = m - 1;
            }else l = m + 1;
        }
        oi(max(temp2-temp1,0));puts("");
        return 0;
    }


  • 相关阅读:
    Idea打包问题
    centos问题总结
    Linux CentOS7 系统目录详解
    centos下修改文件后如何保存退出
    利用windows上的VMware安装CentOS7
    VMware安装系统出现Operating System not found 解决方案
    mybatis 0 变成null问题
    Shiro权限前端调用302重定向
    java版本
    产品画原型工具放入到托管平台
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626058.html
Copyright © 2011-2022 走看看