4768 Jumping Stones

Source: Internet
Author: User

4768 Jumping Stones

time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingTitle Description Description

The annual "Rock-jumping" competition begins again!

The race will be carried out in a straight channel, with some huge rocks in the river. The organizing committee has chosen two rocks as the starting point and end point of the competition. Between the starting and ending points, there are n blocks of rock (rocks without start and end points). In the course of the game, the contestants will start from the starting point and each step jumps to the adjacent rocks until they reach the end point.

In order to improve the difficulty of the game, the organizing committee plans to remove some rocks, so that players in the course of the shortest jump distance as long as possible. Due to budgetary constraints, the organizing committee removes the M-block rock from between the starting point and the end point (the rock cannot be removed from the starting and ending points).

Enter a description Input Description

The input file name is stone.in.

The first line of the input file contains three integer l,n,m, representing the distance from the starting point to the end point, the number of rocks between the start and end points, and the number of rocks removed by the organizing committee.

The next n rows, one integer per line, and the integer Di (0 < di < L) of line I, represent the distance between the block I rock and the starting point. These rocks are given in the order of starting from small to large, and no two rocks will appear in the same position.

Output description Output Description

The output file name is Stone.out.

The output file contains only one integer, which is the maximum value for the shortest hop distance.

Sample input Sample Input

25 5 2

2

11

14

17

21st

Sample output Sample Output

4

Data range and Tips Data Size & Hint

For 20% of data, 0≤m≤n≤10. For 50% of data, 0≤m≤n≤100.

For 50% of data, 0≤m≤n≤100.

For 100% of data, 0≤m≤n≤50,000,1≤l≤1,000,000,000.

#include <cstdio>#include<iostream>using namespacestd;intl,n,m;inta[50005];intL;intCheckintx) {    intLast =0;//last stone to the distance pointing to the stone    intAns =0;  for(intI=1; i<=n;i++)    {        if(a[i]-last<x)//If the distance of the first stone to the previous stone is less than the hypothetical answerans++;//The stone can be moved .        Else//if greater than (that is, the condition is met)last = A[i];//The stone is preserved and the last is assigned the distance from the stone to the origin to calculate the distance from the next stone to it.    }    if(ans>m)return 0; return 1;}intMain () {scanf ("%d%d%d",&l,&n,&m);  for(intI=1; i<=n;i++) scanf ("%d",&A[i]); A[n+1]=l;n++;//we assume that there is the first n+1 stone at the end, then the distance from the beginning is L.    intL=0, r=m;  while(l<=r) {intMid= (L+R)/2; if(Check (mid)) l=mid+1;//The result is small, two points to the right        Elser=mid-1;//The result is big, two points to the left} printf ("%d\n", L-1);}

4768 Jumping Stones

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.