题目大意:
输入n  接下来描述1~n位农夫挤牛奶的开始与结束时间
 
Sample Input

3
300
1000
700 1200
1500 2100

Sample Output

900
300

注意开始结束时间都可能相同 且不一定是按时间顺序的

题解:http://www.xuebuyuan.com/1960543.html

#include <bits/stdc++.h>
using namespace std; struct COW{ int tm,k; }cow[];
bool cmp(COW a,COW b)
{
if(a.tm==b.tm) return a.k>b.k;
return a.tm<b.tm;
} int main()
{
int n;
while(~scanf("%d",&n))
{ int j=;
while(n--)
{
scanf("%d",&cow[j].tm); cow[j++].k=;
scanf("%d",&cow[j].tm); cow[j++].k=;
}
sort(cow+,cow+j,cmp); int key,last,lcon,lid;
key=last=lcon=lid=; for(int i=;i<j;i++)
{
if(cow[i].k) key++;
else key--; if(!key)
{
lcon=max(lcon,cow[i].tm-cow[last+].tm);
lid=max(lid,cow[i+].tm-cow[i].tm);
last=i;
}
}
printf("%d %d\n",lcon,lid);
}
return ;
}

Milking Cows /// 区间计数 离散化排序 oj10105的更多相关文章

  1. Milking Cows 挤牛奶 USACO 排序 模拟

    1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 15  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1 ...

  2. 【USACO】Milking Cows

    Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer b ...

  3. Milking Cows 挤牛奶

    1.2.1 Milking Cows 挤牛奶 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 108[Submit][Status ...

  4. 【洛谷P1204】【USACO1.2】挤牛奶Milking Cows

    P1204 [USACO1.2]挤牛奶Milking Cows 题目描述 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个 ...

  5. Milking Cows

    Milking Cows Three farmers rise at 5 am each morning and head for the barn to milk three cows. The f ...

  6. POJ-2528 Mayor's posters (线段树区间更新+离散化)

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  7. 洛谷P1204 [USACO1.2]挤牛奶Milking Cows

    P1204 [USACO1.2]挤牛奶Milking Cows 474通过 1.4K提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 请各位帮忙看下程序 错误 ...

  8. UVa 1640 The Counting Problem (数学,区间计数)

    题意:给定两个数m, n,求从 m 到 n 中0-9数字各出现了多少次. 析:看起来挺简单的,其实并不好做,因为有容易想乱了.主要思路应该是这样的,分区间计数,先从个位进行计,一步一步的计算过来.都从 ...

  9. codeforce ---A. Milking cows

    A. Milking cows time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. 工具类--map 转成xml xml转成map

    public class WxChatReq { /** * Map转换成XML * @param data * @return * @throws Exception */ public stati ...

  2. bigdecimal解决小数间的加减乘除

    public class bigdecimal { public static BigDecimal div(double v1,double v2){ BigDecimal b1=new BigDe ...

  3. 为了避免hexo博客换了电脑应该提前做的准备。

    个人博客:https://mmmmmm.me 源码:https://github.com/dataiyangu/dataiyangu.github.io 本文转自:https://www.jiansh ...

  4. img路径错误时,用户友好图片

    img 标签的属性里面添加 onerror="this.src='error友好图片'" 就可以了!

  5. Error: EBUSY: resource busy or locked, symlink "xxx" 的解决方法

    上面是报错信息. 解决方法:当我们在npm i 安装依赖的时候,会遇到这个Error: EBUSY: resource busy or locked, symlink....的问题.解决的 办法就是关 ...

  6. 用mybatis进行模糊查询总是查不到结果!

    //IStudentDao.xml @Override public List<Student> selectStudentByName(String name) { SqlSession ...

  7. 【转】手机web页面制作时的注意事项

    一.手机页面的标准头规范 字符编码使用utf-8:指定页面手机内存缓存中的存储时间段 device-width:通知浏览器使用设备的宽度作为可视区的宽度 initial-scale - 初始的缩放比例 ...

  8. Java 序列化和反序列化(三)Serializable 源码分析 - 2

    目录 Java 序列化和反序列化(三)Serializable 源码分析 - 2 1. ObjectStreamField 1.1 数据结构 1.2 构造函数 2. ObjectStreamClass ...

  9. nashorn中js数组转为对象的问题

    背景 在项目中,使用jdk中的nashorn执行javascript脚本,例如如下脚本片段: let ctx = session.ctx; ctx.confirm = { //车牌划分后的数组 seg ...

  10. apache+tomcat配置负载均衡,实现http与websocket接口分压

    一.应用场景 在生产环境中,应用服务器(此文以tomcat为例)不免面临高访问量的压力,相比而言web服务器(此文以apache为例)能够承担更大的并发量.Apache本身带有一些模块,可以完成对应用 ...