2019 cattle race off the sixth D Move macro monotonous, partially monotonous

Move

The meaning of problems

With k the same volume of the box, there is a fixed Han Han packing strategy, each package can be loaded only the weight of the largest things, find the minimum reference box

analysis

Seems to be half, but because of his boxing strategy a bit stupid, so only meet at the macro monotonic, there is no monotonic in particular small range, when the game is also thought not monotonic, but did not think clearly at macroscopic monotone, so had not written a half, on the mentality of collapse, found after the game to find a satisfied as long as the value is about half the minimum will be able to come out too. . . . Still too young

hack: 15 5 • 39 39 39 39 39 60 60 60 60 60 100 100 100 100 100,199 as a legitimate answer, but not the 200, 201 no.

#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
const int maxn=2005;
const int inf=1e7;
int a[maxn];
int n,k;
multiset<int>s;
   
int check(int mid){
    s.clear();
    for(int i=1;i<=n;i++)s.insert(a[i]);
    for(int i=0;i<k;i++){
        /*
            auto it=(--s.end());
            int vl=mid;
            if((*it)>mid){
                return 0;
            }
            vl-=(*it);
            s.erase(it);
        */
   
        int vl=mid;
        if(s.empty())return 1;
        while(vl>0){
            //cout<<vl<<endl;
            auto z=s.upper_bound(vl);
            if(z==s.begin()){
                /*if(*z<=vl){
                    vl-=*z;
                    s.erase(z);
                    cnt++;
                  //  cout<<cnt<<endl;
                    if(s.empty())return 1;
                    break;
                }
                if{
                    break;
                }*/
                break;
            }
            --z;
            //if(*z>vl)break;
            vl-=(*z);
            s.erase(z);
            if(s.empty())return 1;
        }
    }
    if(s.empty())return 1;
    else return 0;
}
int main(){
    int t;
    scanf("%d",&t);
    int kase=1;
    while(t--){
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        sort(a+1,a+1+n);
        int l=1,r=inf,ans=inf;
        while(l<=r){
            int mid=(l+r)>>1;
            if(check(mid)){
                ans=min(ans,mid);
                r=mid-1;
            }
            else l=mid+1;
        }
        for(int i=max(1,ans-100);i<=ans+100;i++){
            if(check(i)){
                ans=i;
                break;
            }
        }
        printf("Case #%d: %d\n",kase++,ans);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/ttttttttrx/p/11407581.html