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. 中证500等主要指数的市盈率(PE)估值高度

    全指医药(SH000991) - 2018-10-18日,当前值:22.8575,平均值:36.88,中位数:36.27655,当前 接近历史新低.全指医药(SH000991)的历史市盈率PE详情 中 ...

  2. MVC5 Entity Framework学习之实现主要的CRUD功能

    在上一篇文章中,我们使用Entity Framework 和SQL Server LocalDB创建了一个MVC应用程序,并使用它来存储和显示数据.在这篇文章中,你将对由 MVC框架自己主动创建的CR ...

  3. Java查找替换文本文件内容

    文本替换几乎是所有文本编辑器都支持的功能,但是要限制在编辑其中才可以执行该功能.本实例实现了制定文本文件的内容替换,并且不需要再编辑其中打开文本文件. 思路: 先看视图层,要有一个JButton控件用 ...

  4. eclipse 安装 ndk 组件

    新安装的eclipse没有ndk组件, 我使用的安装包是:android-ndk32-r10b-windows-x86_64.zip,打开preferences如下

  5. Spark-scala-API

    1.sc.version2.集群对象:SparkContext:获得Spark集群的SparkContext对象,是构造Spark应用的第一步!SparkContext对象代表 整个 Spark集群, ...

  6. VisualSVN破解

    先讲下破解原理 首先,去VisualSVN官网下载最新版本. 传送门:http://www.visualsvn.com/server/download/ 定位到VisualSVN安装目录,C:\Pro ...

  7. RF判断列表、字典、整数、字符串类型是否相同方法

      ${d} create list shk shsh${w} create list ${e} evaluate type(${d}) ${t} evaluate type(${w}) should ...

  8. Redis 操作字符串数据

    Redis 操作字符串数据: > set name "Tom" // set 用于添加 key/value 数据,如果 key 存在则覆盖 OK > setnx nam ...

  9. 3ds Max导出FBX动画模型在OSG中使用

    3ds Max做好动画模型 导出选项:包含-动画-附加选项-勾选使用场景名(这样动画名就是场景名)高级选项-单位-勾选自动(否则导出的模型很小) 导出文件名假设a.fbx使用osgconv工具旋转坐标 ...

  10. html主要笔记

    1.用title属性作为工具提示 2.链接到锚点 <a href="http://wickedlysmart.com/buzz#Coffee"> 3.<em> ...