The Cow Lineup

Time Limit: 1000MS Memory Limit: 30000K

Total Submissions: 5587 Accepted: 3311

Description

Farmer John’s N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1…K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds:

1 5 3 2 5 1 3 4 4 2 5 1 2 3

Farmer John’s acute mathematical mind notices all sorts of properties of number sequences like that above. For instance, he notices that the sequence 3 4 1 3 is a subsequence (not necessarily contiguous) of the sequence of breed IDs above. FJ is curious what is the length of the shortest possible sequence he can construct out of numbers in the range 1..K that is NOT a subsequence of the breed IDs of his cows. Help him solve this problem.

Input

  • Line 1: Two integers, N and K

  • Lines 2..N+1: Each line contains a single integer that is the breed ID of a cow. Line 2 describes cow 1; line 3 describes cow 2; and so on.

    Output

  • Line 1: The length of the shortest sequence that is not a subsequence of the input

    Sample Input

14 5

1

5

3

2

5

1

3

4

4

2

5

1

2

3

Sample Output

3

脑洞题,做这种题目需要灵感。思路就是这个数列中包含1到k所有数字的子序列为一个集合,答案是就是集合数加1

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h> using namespace std;
#define MAX 100000
int a[MAX+5];
int b[MAX+5];
int n,k;
bool judge()
{
for(int i=1;i<=k;i++)
if(b[i]==0)
return false;
return true;
}
int main()
{
int ans;
int num;
while(scanf("%d%d",&n,&k)!=EOF)
{
ans=0;
num=0;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
if(!b[a[i]])
{
b[a[i]]=1;
num++;
}
if(num==k)
{
ans++;
num=0;
memset(b,0,sizeof(b));
} }
printf("%d\n",ans+1);
}
}

poj-1989 The Cow Lineup的更多相关文章

  1. H-The Cow Lineup(POJ 1989)

    The Cow Lineup Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5367   Accepted: 3196 De ...

  2. POJ 3617 Best Cow Line(最佳奶牛队伍)

    POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...

  3. 3377: [Usaco2004 Open]The Cow Lineup 奶牛序列

    3377: [Usaco2004 Open]The Cow Lineup 奶牛序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 16  Solved ...

  4. bzoj 3048[Usaco2013 Jan]Cow Lineup 思想,乱搞 stl

    3048: [Usaco2013 Jan]Cow Lineup Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 237  Solved: 168[Subm ...

  5. bzoj3048[Usaco2013 Jan]Cow Lineup 尺取法

    3048: [Usaco2013 Jan]Cow Lineup Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 225  Solved: 159[Subm ...

  6. BZOJ_3048_[Usaco2013 Jan]Cow Lineup _双指针

    BZOJ_3048_[Usaco2013 Jan]Cow Lineup _双指针 Description Farmer John's N cows (1 <= N <= 100,000) ...

  7. POJ 3268 Silver Cow Party (最短路径)

    POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...

  8. POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。

    POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...

  9. [bzoj 3048] [Usaco2013 Jan]Cow Lineup

    [bzoj 3048] [Usaco2013 Jan]Cow Lineup Description 给你一个长度为n(1<=n<=100,000)的自然数数列,其中每一个数都小于等于10亿 ...

随机推荐

  1. selenium chrome登陆手机 pc淘宝

    接口登录淘宝,困难度极高,没有人已经实现过. 淘宝登录selenium 手机版  pc版. 由于每天需要使用ip代理大批量的异地登录淘宝帐号,这种情况必然会出现淘宝滑动验证码,使用ActionChai ...

  2. Visual Assist X 10.8.2042的Crack破解补丁. 2014.06.25 (General release.)

    VA小组时隔一个月又公布了新的版本号,这个版本号新添加了5个特性,修复了7-8个bug.而且也是稳定的Release版.所以这是很推荐更新的一个版本号. 对于破解补丁还是老规矩,请到我的下载空间下载, ...

  3. 架构设计:系统存储(28)——分布式文件系统Ceph(挂载)

    (接上文<架构设计:系统存储(27)--分布式文件系统Ceph(安装)>) 3. 连接到Ceph系统 3-1. 连接客户端 完毕Ceph文件系统的创建过程后.就能够让客户端连接过去. Ce ...

  4. 如何关闭Struts2的webconsole.html

    出于安全目的,在禁用了devMode之后,仍然不希望其他人员看到webconsole.html页面,则可以直接删除webconsole.html 的源文件, 它的位置存在于: 我们手工删除 strut ...

  5. DDMS调试信息

    1.可以使用System.out.println() 2.android.util包下的Log类 该类可以将信息以日志的形式输出到LogCat中: import android.util.Log; S ...

  6. 第二篇:Hadoop 在Ubuntu Kylin系统上的搭建[图解]

    前言 本文介绍如何在Ubuntu Kylin操作系统上搭建Hadoop平台. 配置 1. 操作系统: Ubuntu Kylin 14.04 2. 编程语言: JDK 1.8 3. 通信协议: SSH ...

  7. javascript的初步认识

    把握自己,就是时时拥有一颗清澈的心,拥有一片明朗的情怀.嘿嘿,我们在2014-2015的跨度里,我们休息了的四天,今天又回到了学习的阶段,敲起来键盘突然有点陌生,想一想时间真的好快,在这里我们已经是跨 ...

  8. centos7/nginx/tornado错误异常收集

    临时方法 – 设置系统参数 使用命令setenforce 附: setenforce 设置SELinux 成为enforcing模式 setenforce 设置SELinux 成为permissive ...

  9. 如何创建圆角 UITextField 与内阴影

    本文转自http://www.itstrike.cn/Question/9309fbd6-ef5d-4392-b361-a60fd0a3b18e.html 主要学习如何创建内阴影 我自定义 UITex ...

  10. IOS设计模式第十篇之命令行设计模式

    命令行设计模式: 命令设计模式将一个请求或行动作封装为对象.这个封装请求比原始的请求要灵活并且可以在对象之前被传递,存储,动态修改或者放进队列里面.苹果 苹果公司实现这种模式使用Target-Acti ...