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\n",l);
36     return 0;
37 }

 

上一篇:Qt连接MySQL代码示例 connectDB


下一篇:【Linux-ZooKeeper】安装&配置参数