| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求大神指点//程序是错的 但是ac
//测试数据
/*25 5 1
2 2
3 14
4 11
5 21
6 17
7
8 25 5 2
9 2
10 14
11 11
12 21
13 17
14
15 25 5 3
16 2
17 14
18 11
19 21
20 17
21
22
23 25 5 4
24 2
25 14
26 11
27 21
28 17
29
30
31 25 5 5
32 2
33 14
34 11
35 21
36 17
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 50005;
int n, m, l;
int a[maxn], dis[maxn];
int BriSearch(int low, int high, int k)
{
while(low <= high){
int mid = (low + high) >> 1;
int len = 0;
int cnt = 0;
for(int i = 1; i <= n; i++)
{
len += dis[i];
if(len < mid)
cnt++;
else
len = 0;
}
if(cnt > m)
high = mid - 1;
else
low = mid + 1;
}
return high;
}
int main()
{
while(scanf("%d %d %d",&l, &n, &m) != EOF)
{
for(int i = 1; i <= n; i++)
scanf("%d",&a[i]);
sort(a + 1, a + n + 1);
a[0] = 0; a[ n + 1] = l;
for(int i = 1; i <= n + 1; i++)
dis[i] = a[i] - a[i - 1];
printf("%d\n",BriSearch(0, l, m));
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator