加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Milking Cows(USACO)

发布时间:2020-12-16 23:14:09 所属栏目:大数据 来源:网络整理
导读:/*ID:tianlin2PROG:milk2LANG:C++*/#include iostream#include fstreamusing namespace std;int main(){ ofstream fout("milk2.out"); ifstream fin("milk2.in"); int be1[5000],end1[5000]; //a为奶牛数,b为不挤奶的时间,c为最长不挤奶的时间,x为至少一个人

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

官方答案:

排序算法很值得学习!

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读