Milking Cows(USACO)

本文介绍了一种计算最长挤奶时间和最长不挤奶时间的方法。通过将挤奶时间段视为数轴上的区间,并采用排序和合并重叠区间的策略,有效地找出最长连续挤奶和不挤奶的时间段。

把时间看过一个数轴,然后合并重复的时间,但是没有排序,没有官方答案的简洁!

 

官方答案:

 

排序算法很值得学习!

 

We read the list of times, sort it by start time, and then walk over the list once, merging overlapping times. Then we walk the list watching for long milking periods and long non-milking periods.

An alternate approach would be to just keep an array of size a million and mark off times. On a nice fast processor, that's probably fast enough, but our above algorithm will work even on slow processors, and it's not much harder to write.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值