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 ...
随机推荐
- HDU—4463 Outlets 最小生成树
In China, foreign brand commodities are often much more expensive than abroad. The main reason is th ...
- <Linux> 下安装和卸载JDK
安装 下载jdk https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 在local ...
- Python 绑定方法与非绑定方法
用到的: import uuid -------------- uuid是128位的全局唯一标识符, 通常用32位的一个字符串的形式来表现 uuid.uuid1() ------------- ...
- Borrowers
Description I mean your borrowers of books - those mutilators of collections, spoilers of the symmet ...
- LeetCode 121. Best Time to Buy and Sell Stock (stock problem)
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- C语言不容易识别的坑
1.重复两次定义 #include<stdio.h> #include<stdlib.h> #include<string.h> int a,b; void fun ...
- SPOJ-BRCKTS (括号序列,线段树)
维护括号序列 Replace(i): 将第i个位置的括号反向. Check:测试当前序列是否合法. 题解 将左括号定为1,右括号定为-1,所以只需要满足前缀和序列没有负数即可,即最小值 为正即可,第i ...
- topshelf生成Windows服务
一. 概述 Visual C# 工程中选取 Windows 服务(Windows Service)选项,可以创建Windows服务程序,这种开发方式对于开发来说不方便调试,今天介绍另外一种生成Win ...
- 【存储过程】MySQL存储过程/存储过程与自定义函数的区别
---------------------------存储过程-------------------- 语法: 创建存储过程: CREATE [definer = {user|current_user ...
- 恢复表数据的办法(delete删除可恢复,truncate不可恢复)
select * from table_name as of timestamp to_timestamp('2018-12-20 00:00:00', 'yyyy-mm-dd hh24:mi:ss' ...