博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pku2456 Aggressive cows
阅读量:7193 次
发布时间:2019-06-29

本文共 1927 字,大约阅读时间需要 6 分钟。

数轴上有n个点,现在有c个点,放在n个点中的c个点中,让c个点中两点间最小距离最大。

这个最大最小问题就真是二分答案了,然后贪心判定即可。

加了一个pascal自身优化{$inline on}把140+ms拉到了90+ms。

View Code
1 {
$inline on} 2 program pku2456(input,output); 3 var 4 x : array[0..100010] of longint; 5 n,c : longint; 6 answer : longint; 7 procedure init; inline; 8 var 9 i : longint; 10 begin 11 readln(n,c); 12 for i:=1 to n do 13 readln(x[i]); 14 end; {
init } 15 procedure swap(var aa,bb :longint ); inline; 16 var 17 tt : longint; 18 begin 19 tt:=aa; 20 aa:=bb; 21 bb:=tt; 22 end; {
swap } 23 procedure sort(p,q : longint); inline; 24 var 25 i,j,m : longint; 26 begin 27 i:=p; 28 j:=q; 29 m:=x[(i+j)>>1]; 30 repeat 31 while x[i]
m do 34 dec(j); 35 if i<=j then 36 begin 37 swap(x[i],x[j]); 38 inc(i); 39 dec(j); 40 end; 41 until i>j; 42 if i
p then sort(p,j); 44 end; {
sort } 45 function check(limit : longint ):boolean; inline; 46 var 47 sum : longint; 48 i,now : longint; 49 begin 50 now:=1; 51 sum:=1; 52 for i:=1 to n do 53 begin 54 if x[i]-x[now]>=limit then 55 begin 56 now:=i; 57 inc(sum); 58 end; 59 if sum>=c then 60 exit(true); 61 end; 62 exit(false); 63 end; {
check } 64 procedure dichotomy; inline; 65 var 66 l,r,mid : longint; 67 begin 68 l:=1; 69 r:=x[n]; 70 while l+1
>1; 73 if check(mid) then 74 l:=mid 75 else 76 r:=mid; 77 end; 78 answer:=l; 79 end; {
dichotomy } 80 procedure print; inline; 81 begin 82 writeln(answer); 83 end; {
print } 84 begin 85 init; 86 sort(1,n); 87 dichotomy; 88 print; 89 end.

转载于:https://www.cnblogs.com/neverforget/archive/2012/03/22/2411335.html

你可能感兴趣的文章
Mybatis generator的使用
查看>>
聊下并发和Tomcat线程数(错误更正)
查看>>
L2-001. 紧急救援(迪杰斯特拉算法)
查看>>
leetcode297. 二叉树的序列化与反序列化
查看>>
bzoj3272 3638
查看>>
bzoj3192
查看>>
Controlled Tournament(状态压缩DP)
查看>>
Mac下,如何把项目托管到github
查看>>
记微软OpenHack机器学习挑战赛
查看>>
new XSSFWorkbook(is); Package should contain a content type part [M1.13]
查看>>
MongoDB安全及身份认证
查看>>
oc精简笔记
查看>>
python的多线程和守护线程
查看>>
traditional:true
查看>>
PS字体加粗的小方法、、
查看>>
构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
查看>>
友元程序集
查看>>
Mysql表编辑
查看>>
规定密码以字母开头只能包含字母、数字和下划线
查看>>
计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task
查看>>