题目大意:
输入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. MySql精简

    安装的是免安装版MySql 由于MySql是开源的,故下载的时候源码也会包含,如果单纯只是使用其功能,则可以将这些文件删除为MySql减肥 可以删除的文件有如下: 1.mysql-test 文件夹: ...

  2. Java-Class-@I:java.annotation.Resource

    ylbtech-Java-Class-@I:java.annotation.Resource 1.返回顶部   2.返回顶部 1.1. import javax.annotation.Resource ...

  3. spring boot开发,jar包一个一个来启动太麻烦了,写一个bat文件一键启动

    spring boot开发,jar包一个一个来启动太麻烦了,写一个bat文件一键启动 @echo offcd D:\workProject\bushustart cmd /c "title ...

  4. 1029 Median (25 分)

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

  5. 使用CSS将图片转换成黑白(灰色、置灰) & 毛玻璃效果

    法1⃣️: IE浏览器: filter: gray; 其他浏览器: .gray { -webkit-filter: grayscale(100%); -moz-filter: grayscale(10 ...

  6. 设置非阻塞的套接字Socket

    当使用socket()函数和WSASocket()函数创建套接字时,默认都是阻塞的.在创建套接字之后,通过调用ioctlsocket()函数,将该套接字设置为非阻塞模式.函数的第一个参数是套接字,第二 ...

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

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

  8. springboot1.5.x升级到2.1.x切换分支导致的maven依赖混乱

    背景:项目springboot版本由1.5.X升级到2.1.X,两个版本的分支需要共存,来回切换的时候,maven依赖各种报红 查看dependency发现1.5.X的jar和2.1.X的jar都存在 ...

  9. LNMP之PHP

    PHP LNMP环境下的PHP安装 CGI指的是通用网关接口,为HTTP服务器与其他机器上的程序服务通信交流的一种工具,性能差,所以被淘汰了. FastCGI,是一个可以伸缩.高速的在HTTP服务器和 ...

  10. C#实体类克隆

    public static T Clone<T>(T source) { if (!typeof(T).IsSerializable) { throw new ArgumentExcept ...