P2672 jump stone

This is a dichotomous answer 2015noip topic, read explanations will ,,

Stone title given location and lets you jump forward stepping stone, a rock also delete up to m can go through, to solve the maximum shortest distance of the jump.

What then two minutes it: mid to jump length. Then left = 0, right = l for two minutes. Retake s are recorded and now move the current number of stones, can determine whether to jump over (and similar ideas prefix). Finally moved such that the stones current hop> = m, then letting right = mid-1, if the move is <= m, then the current record mid, left = mid + 1. And because the topic that is the maximum value of the minimum distance, then finally found is the greatest.

1. Determine what the subject may be binary EG. The largest minimum, k preferably, the amount of the key monotone minimum average road. .

2. What is solving half of what

3. how to change about half of endpoint

4. Carefully read the title, and so at least most promising keywords, the clear logic

#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define maxn 600000
using namespace std;
int m,n;
int l,d;
int left,right,mid;
int a[maxn];
int s,now;
int ans=0;
int main(){
    cin>>l>>n>>m;    
    for(int i=1; I <= n-; I ++ ) { 
        CIN >> A [I]; 
    } 
    int left = 0 , right = L;
     the while (left <= right) { // half hop length 
        MID = (left + right) / 2 ; 
        now = 0 ; // skip the first few 
        S = 0 ; // moved several stones 
        for ( int I = . 1 ; I <= n-; I ++ ) {
             IF (a [I] -a [now] <MID ) { // If the jump over 
            S ++; // move 
            }
            else{
                now=i;
            } 
        }
        if(s<=m){
            ans=mid;
            left=mid+1;
        }
        else right=mid-1; 
    }
    cout<<ans;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/china-mjr/p/11615950.html