Usaco 1.2.1 挤牛奶(Milking Cows)
2011-08-05 08:53
465 查看
题目: | 挤牛奶 | |
来源: | Usaco1.2.1 | |
题目大意: | 给定N个人,每个人有个开始时间和结束时间,求最长的无人时间和最长的有人时间 | |
数据范围: | 1<=N<=5000,时间小于1000000 | |
样例: | 3 3001000 7001200 15002100 | 900300 |
做题思路: | 本来一看想用线段树,一想太麻烦就换了,原来直接按开始时间排序然后直接模拟就好,这个叫离散化?貌似吧 | |
知识点: | 线段树、快排、模拟、离散化、搜索 |
ID:DountNameless
TASK:milk2
LANG:PASCAL
}
type
act=record
st,ed:longint;
end;
var
i,j,st,ed,ans,ans1,n:longint;
a:array[0..5010]ofact;
procedureqsort(l,r:longint);{<快排不解释>}
var
i,j,k:longint;
t:act;
begin
i:=l;j:=r;k:=a[(l+r)div2].st;
repeat
whilea[i].st<kdoinc(i);
whilea[j].st>kdodec(j);
ifi<=jthen
begin
t:=a[i];a[i]:=a[j];a[j]:=t;
inc(i);dec(j);
end;
untili>j;
ifi<rthenqsort(i,r);
ifj>lthenqsort(l,j);
end;
begin
assign(input,'milk2.in');reset(input);
assign(output,'milk2.out');rewrite(output);
readln(n);
fori:=1tondo
readln(a[i].st,a[i].ed);
qsort(1,n);
st:=a[1].st;ed:=a[1].ed;{<先手动记录第一个时间>}
ans:=ed-st;
fori:=2tondo
begin
ifed>=a[i].stthen
begin
ifed<a[i].edthened:=a[i].ed;{<下一个人的开始时间小于该人的结束时间则相连>}
end
else
begin{<否则更新答案>}
ifans<(ed-st)thenans:=ed-st;
ifans1<(a[i].st-ed)thenans1:=a[i].st-ed;
st:=a[i].st;ed:=a[i].ed;
end;
end;
writeln(ans,'',ans1);
close(input);close(output);
end.题目来源:
相关文章推荐
- USACO 1.2.1 Milking Cows 挤牛奶
- USACO1.2.1 Milking Cows(挤牛奶)
- usaco 1.2.1 Milking Cows 挤牛奶
- USACO1.2.1 Milking Cows (milk2)
- USACO 1.2.1 Milking Cows
- 【USACO1.2_1】★Milking Cows 挤牛奶
- USACO 1.2.1 Milking Cows(milk2)
- USACO——Milking Cows 挤牛奶
- USACO 1.2.1 Milking Cows
- usaco 1.2.1 Milking Cows
- USACO——Milking Cows 挤牛奶
- [USACO1.2]挤牛奶Milking Cows 差分
- USACO 1.2.1 Milking Cows
- USACO1.2.1--Milking Cows
- [USACO 1.2.1]挤牛奶
- USACO1.2.1 Milking Cows (milk2)
- 【区间计数】Milking Cows 挤牛奶 (milk2) Usaco_Training 1.2
- USACO 1.2.1 Milking Cows
- USACO之Section1.2.1 Milking Cows [其他]
- [USACO 1.2.1] Milking Cows