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 ...
随机推荐
- mysql jdbc驱动与java 版本对应关系
当使用某些密码套件时,Connector/J5.1需要JRE 1.8.x才能使用SSL/TLS连接到MySQL 5.6,5.7和8.0.
- [Python3网络爬虫开发实战] 3.3-正则表达式
本节中,我们看一下正则表达式的相关用法.正则表达式是处理字符串的强大工具,它有自己特定的语法结构,有了它,实现字符串的检索.替换.匹配验证都不在话下. 当然,对于爬虫来说,有了它,从HTML里提取想要 ...
- 零基础入门学习Python(30)--文件系统:介绍一个高大上的东西
知识点 os,os.path模块中关于文件.目录常用的函数使用方法 在使用os模块,需要先进行import操作: import os os模块中关于文件/目录常用的函数使用方法 函数名 函数作用 示例 ...
- uva 12096 The SetStack Computer(STL set的各种库函数 交集 并集 插入迭代器)
题意: 有5种操作: PUSH:加入“{}”空集合入栈. DUP:栈顶元素再入栈. UNION:出栈两个集合,取并集入栈. INTERSECT:出栈两个集合,取交集入栈. ADD:出栈两个集合,将先出 ...
- prometheus监控mysql
创建一个用于mysqld_exporter连接到MySQL的用户并赋予所需的权限 mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO '; my ...
- 【转】Java的path,classpath,java_home环境变量的配置与具体含义
对于一个Java初学者来说,第一步要做的是安装jdk并配置环境变量,一般按照书上或者网上的步骤,一步步照着做就行了,但是对于初学者来说,很多问题没有解决,比如为什么很多配置方法各不相同,却都能够配置成 ...
- [luoguP1045] 麦森数(快速幂 + 高精度)
传送门 这道题纯粹是考数学.编程复杂度不大(别看我写了一百多行其实有些是可以不必写的). 计算位数不必用高精时刻存,不然可想而知时间复杂度之大.首先大家要知道一个数学公式 logn(a*b)=logn ...
- 利用mysql分析小规模数据
1 获取数据 示例:(/home/work/data/1.data) 123457,chenli,70 123458,liuyang,71 2 create table CREATE TABLE sc ...
- Thinkphp5.0 的实践一
Thinkphp5.0 的实践一 tp5.0默认没有__SELF__,需要定义, define('__SELF__',strip_tags($_SERVER['REQUEST_URI'])); tp5 ...
- Python基础之 一 补充
三元运算: 语法:result = 值1 if 条件 else 值2 当条件为真时,result = 值1 当条件为假时,result = 值2 进制: 二进制:01 八进制:01234567 十进制 ...