标记数组(哈希)

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. python - 数据驱动测试 - ddt

    # -*- coding:utf-8 -*- ''' @project: jiaxy @author: Jimmy @file: study_ddt.py @ide: PyCharm Communit ...

  2. adb devices 找不到夜神模拟器解决方法

    先打开命令行窗口,输入adb devices,查看连接信息,大致意思是sdk的adb版本与夜神的adb版本不一致,导致. C:\Users\cz9025>adb devices List of ...

  3. 听说你的模型损失是NaN

    听说你的模型损失是NaN 有时候,模型跑着跑着,损失就莫名变NaN了.不过,经验告诉我们,大部分NaN主要是因为除数是0或者传给log的数值不大于0.下面说说是log出NaN的几种常见解决方法. 毕竟 ...

  4. String、StringBuffer和StringBuilder,定义一个自己的StringBuilder的类

    String Java中的字符串值属于String类,虽然有其它方法表示字符串(如字符数组),但Java一般使用String类作为字符串的标准格式,Java编译器把字符串值作为String对象; St ...

  5. 九度oj 题目1494:Dota

    题目描述: 大家都知道在dota游戏中,装备是对于英雄来说十分重要的要素. 英雄们不仅可以购买单个的装备,甚至某些特定的装备组合能够合成更强的装备. 为了简化问题,我们将每个装备对于英雄的功能抽象为一 ...

  6. 【Luogu】P2596书架(Splay)

    题目链接 通过这题我加深了对Splay的理解,原来Splay的子树也是可以接来接去接到别的点上的,而不是只能旋转qwq 具体接的办法就是swap大法. 对于Top操作我们把当前节点Splay到根,然后 ...

  7. Codeforces 899B Months and Years

    题目大意 给定 $n$($1\le n\le 24$)个正整数 $a_1,\dots, a_n$ 判断 $a_1$ 到 $a_n$ 是否可能为连续 $n$ 个月份的天数. 解法 由于 $n\le 24 ...

  8. HDU——2064汉诺塔III

    汉诺塔III Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  9. NOJ——1627Alex’s Game(II)(尺取)

    [1627] Alex’s Game(II) 时间限制: 2000 ms 内存限制: 65535 K 问题描述 Alex likes to play with one and zero as you ...

  10. 【CCF】无线网络 搜索

    [思路] 多个起点同时四周扩展广搜,注意会爆int [AC] #include<iostream> #include<cstdio> #include<cstring&g ...