poj-1989 The Cow Lineup
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.
OutputLine 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的更多相关文章
- H-The Cow Lineup(POJ 1989)
The Cow Lineup Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5367 Accepted: 3196 De ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
- 3377: [Usaco2004 Open]The Cow Lineup 奶牛序列
3377: [Usaco2004 Open]The Cow Lineup 奶牛序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 16 Solved ...
- bzoj 3048[Usaco2013 Jan]Cow Lineup 思想,乱搞 stl
3048: [Usaco2013 Jan]Cow Lineup Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 237 Solved: 168[Subm ...
- bzoj3048[Usaco2013 Jan]Cow Lineup 尺取法
3048: [Usaco2013 Jan]Cow Lineup Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 225 Solved: 159[Subm ...
- BZOJ_3048_[Usaco2013 Jan]Cow Lineup _双指针
BZOJ_3048_[Usaco2013 Jan]Cow Lineup _双指针 Description Farmer John's N cows (1 <= N <= 100,000) ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
- [bzoj 3048] [Usaco2013 Jan]Cow Lineup
[bzoj 3048] [Usaco2013 Jan]Cow Lineup Description 给你一个长度为n(1<=n<=100,000)的自然数数列,其中每一个数都小于等于10亿 ...
随机推荐
- 安装程序配置服务器失败。参考服务器错误日志和C:\windows\sqlstp.log 了解更多信息
重装sql经常遇到2个问题 1,以前的某个程序安装已在安装计算机上创建挂起的文件操作.运行安装程序之前必须重新启动计算机. 删除C:\Program Files\Microsoft SQL Serve ...
- Dubbo调用链(version:2.5.3)
Consumer 调用 Provider的过程: (CONSUMER)Dubbo服务调用处 --> 调用RPC代理 --> InvokerInvocationHandler#invoke( ...
- swoole的进程模型架构
swoole的强大之处就在与其进程模型的设计,既解决了异步问题,又解决了并行. 主线程MainReactor swoole启动后主线程会负责监听server socket,如果有新的连接accept, ...
- flexbox子盒子order属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- The list of pre-build cross-compiler
Recently, I need compile toybox and busybox for my router. This is a list of cross-compiler for MIPS ...
- 转载mysql数据库配置优化
网上有很多的文章教怎么配置MySQL服务器,但考虑到服务器硬件配置的不同,具体应用的差别,那些文章的做法只能作为初步设置参考,我们需要根据自己的情况进行配置优化,好的做法是MySQL服务器稳定运行了一 ...
- hydra 及相关示例
http://www.cnblogs.com/mchina/archive/2013/01/01/2840815.html https://www.thc.org/thc-hydra/ 语法 # hy ...
- Splash args 属性
args属性可以获取加载时配置的参数,一般我们只传入URL,如下,args.url 就相当于加载时配置的URL参数,我们把它赋值给 url 变量然后返回:
- Python进阶 学习笔记(二)
(涉及内容:面向对象,类的继承) 定义类并创建实例 在Python中,类通过 class 关键字定义.以 Person 为例,定义一个Person类如下: class Person(object): ...
- ajax二级联动代码实例
//二级联动 $(function () { var _in_progress = false; function check_in_progress() { if (_in_progress == ...