大厅安排(normal)
Time Limit:1000MS Memory Limit:65536K
Total Submit:210 Accepted:96
Description
有一个演讲大厅需要GEORGE管理,演讲者们事先定好了需要演讲的起始时间和中止时间。GEORGE想让演讲大厅得到最大可能的使用。我们要接受一些预定而拒绝其他的预定,目标自然是使演讲者使用大厅的时间最长。为方便起见,假设在某一时刻一个演讲结束,另一个演讲就可以立即开始。
计算演讲大厅最大可能的使用时间。
Input
第一行为一个整数n,n <= 100,表示申请的数目。
Output
一个整数,表示大厅最大可能的使用时间。
Sample Input
12
1 2
3 5
0 4
6 8
7 13
4 6
9 10
9 12
11 14
15 19
14 16
18 20
Sample Output
16
这题需要利用到快排,排序结束时间
var
i,j,n,max:longint;
a:array[0..1001,1..2]of longint;
f:array[0..1001]of longint;
procedure qsort(l,r:longint);
var
i,j,temp,key:longint;
begin
if l>r then exit;
i:=l; j:=r;
key:=a[(l+r) div 2,2];
repeat
while (a[i,2]<key) do inc(i);
while (a[j,2]>key) do dec(j);
if i<=j then
begin
temp:=a[i,1];a[i,1]:=a[j,1];a[j,1]:=temp;
temp:=a[i,2];a[i,2]:=a[j,2];a[j,2]:=temp;
inc(i);dec(j);
end;
until i>j;
qsort(l,j);
qsort(i,r);
end;
begin
readln(n);
for i:=1 to n do
readln(a[i,1],a[i,2]);
qsort(1,n);
for i:=1 to n do
begin
max:=0;
for j:=1 to i-1 do
if (f[j]>max)and(a[i,1]>=a[j,2]) then max:=f[j];
f[i]:=max+a[i,2]-a[i,1];
end;
max:=0;
for i:=1 to n do
if f[i]>max then max:=f[i];
write(max);
end.

2662

被折叠的 条评论
为什么被折叠?



