题目大意:
输入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. yum 快速LAMP/LNMP 安装(centos7+mysql5.7+apache+php5.6 (缺点:好多模块没有加载)

    1.安装Apache 安装centos7默认自带(Apache2.4.6)版本 yum -y install httpd 2.开启apache服务 systemctl start httpd.serv ...

  2. DOS和DDOS攻击

    1.什么是DOS攻击 首先注意这里是DOS(Denial Of Service)攻击,并非DoS.DoS是微软早期的系统版本. DoS即Denial Of Service,拒绝服务的缩写.DoS是指故 ...

  3. Jmeter json和正在提取及断言

    Jmeter  json和正在提取及断言 一.提取所需要断言的内容: 响应数据如下:加入需要提取userid为10477的值 { "pub": { , ", " ...

  4. JAVA学习之环境搭建

    了解到JAVA语言的跨平台性的原理是通过在不同的操作系统中安装对应版本的的JAVA虚拟机(JVM)实现 开发JAVA前必须先搭建JAVA环境: 1.JAVA开发工具包JDK(JAVA DEVELOPM ...

  5. PAT_A1130#Infix Expression

    Source: PAT A1130 Infix Expression (25 分) Description: Given a syntax tree (binary), you are suppose ...

  6. Java标准输入/输出/错误流

    只要使用OutputStream对象就可使用System.out和System.err对象引用.只要可以使用InputStream对象就可以使用System.in对象. System类提供了三个静态设 ...

  7. 当引入的类库存在一个类型时,提示“xxx”和“xxx”之间的不明确引用时,消除歧义的方法

    //using _2_命名空间和程序集.WidgetA; //using _2_命名空间和程序集.WidgetB; using System; using System.Collections.Gen ...

  8. centos 时区设置初认识

    由于一些需要,我租用了一个海外服务器,并开始了我的centos之旅. 由于之前一直用虚拟机,而且在国内,所以不需要考虑时区的问题,但是现在,这个服务器是在海外的,所以就必须考虑时区的问题了.更何况我的 ...

  9. Flask理论基础(一)视图函数和URL反转函数(url_for)

    一.视图函数 1.1 基本用法试图函数是 app.route 或者 bp.route(蓝图)装饰器装饰的函数.该函数实现了对URL路径的转换,也就是路由功能,例如下面代码定义了默认url ‘/’ 和‘ ...

  10. Python 分布式锁

    1,数据一致性 当多个进程/线程对同一个共享资源读写,会因为资源的争夺而出现混乱,导致数据不一致. 如下图: 在数据库的原始数据是 d0,上图的处理流程如下: t1 时刻,有两个数据源的数据 d1,d ...