Poj river hopscotch (max value minimized)

Source: Internet
Author: User

River hopscotch


Link: Click Here ~

Question Analysis:

Given the N coordinate, fixed the start point (0) at the end point (given by the question) requires that M coordinates be deleted to maximize the minimum distance between the remaining two adjacent coordinates. Calculate the maximum value.


Train of Thought Analysis:

I don't know why I think of the value with the maximum minimum distance of the binary enumeration. Below we assume it is D. What should we do?

1. First, we can use binary to get the D.

2. According to function C: the maximum distance that can meet the conditions

# Include <iostream> # include <algorithm> # include <cstdio> # include <cstring> using namespace STD; const int maxn = 50000 + 10; const int INF = ~ 0u> 2; int N, M, L; int d [maxn]; bool C (INT d) {// determine whether the distance d meets int CNT = 0, pos = 0; For (INT I = 0; I <= N; ++ I) {If (d [I]-pos <D) ++ CNT; else Pos = d [I];} return CNT <= m;} void solve () {sort (D, D + n); D [N] = L; int lB =-1, UB = inf; while (UB-lb> 1) {// binary D int mid = (Lb + UB)/2; if (C (MID) lB = mid; else UB = mid;} printf ("% d \ n", LB);} int main () {While (~ Scanf ("% d", & L, & N, & M) {for (INT I = 0; I <n; ++ I) scanf ("% d", & D [I]); solve ();} return 0 ;}

Zookeeper

Poj river hopscotch (max value minimized)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.