zoukankan      html  css  js  c++  java
  • luogu P2678 跳石头 二分答案

     1 #include <cstdio>
     2 using namespace std;
     3 int a[51000];
     4 int len,m,n;
     5 bool check(int x)
     6 {
     7     int last = 0;
     8     int ans = 0;
     9     for (int i = 1;i <= n;i++)
    10     {
    11         if (a[i] - last < x)
    12             ans++;
    13         else
    14             last = a[i];
    15     }
    16     if (ans > m)
    17         return false;
    18     return true;
    19 }
    20 int main()
    21 {
    22     scanf("%d%d%d",&len,&n,&m);
    23     for (int i = 1;i <= n;i++)
    24         scanf("%d",&a[i]);
    25     a[++n] = len;
    26     int l = 0,r = len;
    27     while (l < r)
    28     {
    29         int mid = l + r + 1>> 1;
    30         if (check(mid))
    31             l = mid;
    32         else
    33             r = mid - 1;
    34     }
    35     printf("%d
    ",l);
    36     return 0;
    37 }
    心之所动 且就随缘去吧
  • 相关阅读:
    Mybatis学习笔记14
    Mybatis学习笔记13
    Mybatis学习笔记12
    poj 2513
    poj 2001
    poj 1080
    poj 1703
    poj 1521
    poj 1384
    poj 1726
  • 原文地址:https://www.cnblogs.com/iat14/p/11230824.html
Copyright © 2011-2022 走看看