USACO Section 1.2PROB Miking Cows
贪心做过去,先对每个时间的左边点进行排序,然后乱搞,当然线段树也可以做
/*
ID: jusonal1
PROG: milk2
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
struct node{
int left;
int right;
bool operator<(const node& T)const{
return left < T.left;
}
};
int n;
const int maxn = 5000 + 100;
node cow[maxn];
int main () {
freopen("milk2.in","r",stdin);
freopen("milk2.out","w",stdout);
scanf("%d",&n);
for(int i = 1;i <= n;++i) scanf("%d%d",&cow[i].left,&cow[i].right);
sort(cow + 1,cow + 1 + n);
int cont_time = cow[1].right - cow[1].left,idle_time = 0;
int start = 0,end = 0;
int blank_sum = 0;
start = cow[1].left;
end = cow[1].right;
for(int i = 1;i <= n;++i){
if(cow[i].left > end ){
idle_time = max(idle_time,cow[i].left - end);
start = cow[i].left;
end = cow[i].right;
}
else if(cow[i].right > end){
end = cow[i].right;
}
cont_time = max(cont_time,end - start);
}
printf("%d %d\n",cont_time,idle_time);
return 0;
}
USACO Section 1.2PROB Miking Cows的更多相关文章
- USACO Section 1.2 Milking Cows 解题报告
题目 题目描述 有3个农夫每天早上五点钟便起床去挤牛奶,现在第一个农夫挤牛奶的时刻为300(五点钟之后的第300个分钟开始),1000的时候结束.第二个农夫从700开始,1200结束.最后一个农夫从1 ...
- USACO Section 1.2PROB Transformations
挺有趣的一道题,呵呵,不算难 /* ID: jusonal1 PROG: transform LANG: C++ */ #include <iostream> #include <f ...
- [BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)
[BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yu ...
- NC24017 [USACO 2016 Jan S]Angry Cows
NC24017 [USACO 2016 Jan S]Angry Cows 题目 题目描述 Bessie the cow has designed what she thinks will be the ...
- USACO Section 5.1 Fencing the Cows(凸包)
裸的凸包..很好写,废话不说,直接贴代码. ----------------------------------------------------------------------------- ...
- USACO section1.2 Miking cows
/* ID: vincent63 LANG: C TASK: milk2 */ #include <stdio.h> #include<stdlib.h> #include&l ...
- USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)
usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...
- USACO Section 3.3: Riding the Fences
典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...
- USACO Section 4.2 The Perfect Stall(二分图匹配)
二分图的最大匹配.我是用最大流求解.加个源点s和汇点t:s和每只cow.每个stall和t 连一条容量为1有向边,每只cow和stall(that the cow is willing to prod ...
随机推荐
- centos下安装redis(记录其中踩坑的过程)
一.先下载到redis-3.0.4.tar.gz包(本文以3.0.4版本为例) 我将这个包放在/opt目录下,在/opt下并解压这个包 tar -zxvf redis-.tar.gz 然后进入redi ...
- 微信小程序 video组件----真机测试position:fixed无效 且有黑底
1.问题描述 video组件fixed后,视频随页面滚动,且有个黑色底停留在页面. 页面滚动前 滚动后 这里贴一下修改前代码,在微信开发者工具看是没有任何问题的.在手机端测试就有以上的问题 <v ...
- poj 2186 强连通分量
poj 2186 强连通分量 传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 33414 Acc ...
- //……关于promise
什么是promise? promise 翻译成中文的意思是 "承诺" ,一个承诺说出去了说明他是进行中的,承诺兑现了代表成功,没有兑现代表失败了. promise 对象的状态一旦发 ...
- 将文件大小kb转换成M
得到文件的大小的一般是直接到得到的是文件的字节大小,也就是kb,我们有的时候需要做单位换算成B或者M, 下面方法只是换成M,没有到G, 有更好的方法,请随时沟通,以便交流学习,谢谢. public s ...
- 如何抓取崩溃的log日志
4.手机录屏工具的推荐 Andriod:录屏大师,易录屏等等. iOS:AirPlayer,iTools. 5.如何抓取崩溃的log日志? android闪退获取日志方法: 1.下载adb工具包 2. ...
- 全文搜索(A-3)-用户建模
用户模型可以分为静态模型.动态模型.混合推荐用户模型. 静态模型往往通过显式方式收集用户偏好信息: 动态模型通过隐式方式收集用户偏好信息: 基于内容的用户系统的推荐模型: 关键字匹配,空间向量模型 协 ...
- 《C语言程序设计(第四版)》阅读心得(三)
第八章 指针 1.一个变量的地址称为该变量的指针 一个专门用来存放另一变量的地址(即指针),称它为指针变量.指针变量的值是指针(即地址) 如上图2000是变量的指针,pointer是指针变量, 赋值 ...
- [luoguP1388] 算式(DP)
传送门 看这个n<=15本以为是个状压DP 还是too young 这个题最神奇的地方是加括号是根据贪心的策略. 发现只有在一连串的加号两边加上括号才是最优的(想一想,为什么?) f[i][j] ...
- 【bzoj2152】聪聪可可 点分治
[bzoj2152]聪聪可可 2014年9月7日3,5472 Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是 ...