标记数组(哈希)

1e6的范围,开一个char数组全然能够,有人为1,无人为0,注意边界就可以。最后线性扫描就可以。

时间复杂度,应该是O(n),n为最后结束的时间。

缺点就是……比較慢

/*
ID:twd30651
PROG:milk2
LANG:C++
*/
#include<iostream>
#include<fstream>
#include<string.h>
#include<stdlib.h>
char a[1000001];
using namespace std;
int N;
int main(int argc,char *argv[])
{
freopen("milk2.in","r",stdin);
freopen("milk2.out","w",stdout);
scanf("%d",&N);
memset(a,0,sizeof(a));
int start;
int end;
int mins=1000000;
int maxe=0;
for(int i=0;i<N;++i)
{
scanf("%d",&start);
scanf("%d",&end);
if(start<mins)mins=start;
if(end>maxe)maxe=end;
for(int j=start;j<end;++j)
a[j]=1;
}
int max1=0;
int max2=0;
int l1=0;
int l2=0;
int flag1=1;
int flag2=0;
int i=1;
//printf("%d %d\n",mins,maxe);
for(i=mins;i<maxe;++i)
{
if(flag1==a[i])
{
++l1;
if(l1>max1)max1=l1;
}
else
l1=0;
if(flag2==a[i]) {
++l2;
if(l2>max2)max2=l2;
}
else
{
l2=0;
}
}
printf("%d %d\n",max1,max2);
return 0;
}

USACO 1.2 Milking Cows (枚举)的更多相关文章

  1. USACO Section1.2 Milking Cows 解题报告

    milk2解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

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

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

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

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

  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. codeforce ---A. Milking cows

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

  7. 【题解】Luogu P1204 [USACO1.2]挤牛奶Milking Cows

    原题传送门:P1204 [USACO1.2]挤牛奶Milking Cows 实际是道很弱智的题目qaq 但窝还是觉得用珂朵莉树写会++rp(窝都初二了,还要考pj) 前置芝士:珂朵莉树 窝博客里对珂朵 ...

  8. Milking Cows 挤牛奶

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

  9. NC25136 [USACO 2006 Ope B]Cows on a Leash

    NC25136 [USACO 2006 Ope B]Cows on a Leash 题目 题目描述 给定如图所示的若干个长条.你可以在某一行的任意两个数之间作一条竖线,从而把这个长条切开,并可能切开其 ...

随机推荐

  1. 微信小程序开发 -- 点击右上角实现转发功能

    // 在page的js文件中加入以下代码/** * 用户点击右上角分享 */ onShareAppMessage: function () { }

  2. 设计模式之工厂模式 Factory实现

    simpleFactory //car接口 public interface Car { void run(); } //两个实现类 public class Audi implements Car{ ...

  3. [python 函数学习篇] 关键字参数

    函数可以通过 关键字参数 的形式来调用,形如 keyword = value .例如,以下的函数: def parrot(voltage, state='a stiff', action='voom' ...

  4. spring AOP详解一

    AOP是Aspect Oriented Programing的简称,面向切面编程.AOP适合于那些具有横切逻辑的应用:如性能监测,访问控制,事务管理以及日志记录.AOP将这些分散在各个业务逻辑中的代码 ...

  5. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  6. 【转】Unicode utf8等编码类型的原理

    原文地址http://www.cnblogs.com/daxiong2014/p/4768681.html Unicode utf8等编码类型的原理 1.ASCII码  我们知道,在计算机内部,所有的 ...

  7. 九度oj 题目1458:汉诺塔III

    题目描述: 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动 ...

  8. Welcome-to-Swift-04集合类型(Collection Types)

    Swift提供了两种集合类型来存放多个值——数组(Array)和字典(Dictionary).数组把相同类型的值存放在一个有序链表里.字典把相同类型的值存放在一个无序集合里,这些值可以通过唯一标识符( ...

  9. HDU——2056Rectangles(几何计算)

    Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. hdu 3874 Assign the task

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...