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 ...
随机推荐
- 对拍 bat命令快速模板
对拍.bat @echo off :loop maker.exe > in.in wq.exe < in.in > out.out std.exe < in.in >st ...
- AC手动机 [原创]
题目背景 Monster_Qi 又双叒叕拿到了rank1! 在开心之余他决定帮助蒟蒻floatiy拿到合适的排名. 题目描述 已知考试有n道题,每道题有num个测试点,有m个人 b[x,i,j](01 ...
- Java的类加载
虚拟机把描述类的数据从Class文件加载到内存,并对数据进行校验.转换解析和初始化,最终形成可以被虚拟机直接使用的Java类型,这就是Java虚拟机的类加载机制 ----类加载的大致过程 类的加载的过 ...
- mysql解决 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)的报错
一般这个错误是由密码错误引起,解决的办法自然就是重置密码. 假设我们使用的是root账户. 1.重置密码的第一步就是跳过MySQL的密码认证过程,方法如下: #vim /etc/my.cnf(注:wi ...
- Buffer.from()
Buffer.from(array) array {Array} 使用一个8位字节的数组分配一个新的 Buffer. const buf = Buffer.from([0x62, 0x75, 0x66 ...
- Python之爬虫-中国大学排名
Python之爬虫-中国大学排名 #!/usr/bin/env python # coding: utf-8 import bs4 import requests from bs4 import Be ...
- vim学习之旅01-文本搜索并高亮显示
step 1:在linux终端新建一个test.txt文本文档:vim test.txt; 回车后打开编辑器: step 2:进入编辑状态(键盘"i")输入一段文本,退出编辑(键盘 ...
- Windows 10 & Game Bar & YouTube & video records
Windows 10 & Game Bar & YouTube & video records Windows 10 C:\Users\xgqfrms\Videos\Captu ...
- 算法(1):查找&排序
算法(Algorithm):一个计算过程,解决问题的方法 程序 = 数据结构+算法 时间复杂度: 当算法过程中出现循环折半的时候,复杂度式子中会出现 O(logn) 时间复杂度小结: 1. 时间复杂度 ...
- 欧拉 路径&&回路
不管 欧拉回路 还是 欧拉路径 无向图或者有向图(删除方向后)要联通 欧拉路径存在的判定条件 1 无向图 度数为奇数的点最多有两个 2 有向图 最多只能有两个点的入度不等于出度 ...