ICPC Asia HongKong 2017 E title

Topic Link   https://nanti.jisuanke.com/t/40401

Look question explanation is binary search greedy +

That Italy: choose l s numbers from the number of years, so that the absolute value of the difference between any two of the minimum value of the maximum (somewhat convoluted / scratching) to maximize the minimum

I do question when thinking about how to select it s numbers, the feeling should start from the middle of these numbers, but did not know the supposed. . .

Half the final answer, whether we can finish all the base stations put

code show as below

That you assume an answer, by the base station to determine whether the half finished building to determine the answer is correct.

#include <the iostream> 
#include <algorithm>
 the using  namespace STD; 

int LOC [ 100005 ];
 int n-, C; 

BOOL Test ( int len) {
     int P = 0 ; // first base station on a p [0];
     int Q = the C- . 1 ; 

    for ( int I = . 1 ; I <n-; I ++ ) {
         IF (LOC [I] - LOC [p]> = len) {// should be at least greater than a distance behind the front of the distance 
            p = I; 
            Q - ;
             IF (Q == 0) return true;
        }
    }
    return false;
}

int main() {

    while(cin>>n>>c, n||c){
        for(int i=0; i<n; i++){
                cin>>loc[i];
            }
            sort(loc, loc+n);
            int l = 0;
            int r = location[n-1];
            int mid = 0;

            while(r-l!=1){
                    mid = (l + r)>>1;//除2?
                    if(test(mid)){
                        l = mid;
                    } else {
                        r = mid;
                    }
            }
            cout << l << endl;
    }
    getchar();
    getchar();
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/yz-lucky77/p/11284943.html