Milking Cows(USACO)

来源:互联网 发布:蚁群算法matlab工具箱 编辑:程序博客网 时间:2024/05/17 01:01

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

 

官方答案:

 

排序算法很值得学习!

 

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.

原创粉丝点击