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亿 ...
随机推荐
- 用python开发android应用 【转载】
用python开发android应用 [转载] 转载自:http://www.miui.com/thread-995114-1-1.html Python是动态语言,比较简洁.Android不直接支持 ...
- C#------如何处理缺少对公共可见类型或成员的xml注释的警告
出现警告的原因: 使用Swagger框架时 如图,只要加上注释就可以了 使用前: 使用后:
- Explaining Delegates in C# - Part 7 (Asynchronous Callback - Way 4)
This is the final part of the series that started with... Callback and Multicast delegatesOne more E ...
- Splash images_enabled 属性
images_enabled属性用于设置加载页面时是否加载图片,如下,禁止之后,返回的页面截图就不会带有任何图片,加载速度也会快很多 function main(splash, args) splas ...
- N76E003的学习之路(一)
N76E003是8051内核的一款单片机MCU,它提供丰富的特殊功能模块,包括: 1KRAM其中包括256字节SRAM,768字节XRAM. 最多可达18个标准管脚. 两组标准16位定时器/计数器:定 ...
- java 读写文件例子
在linux下可以读写中文 import java.io.*; import java.text.SimpleDateFormat; import java.util.*; public class ...
- 解决3 字节的 UTF-8 序列的字节 3 无效
maven项目编译正常,运行时候报以下错误: 3 字节的 UTF-8 序列的字节 3 无效 仔细看这个错误的详细信息,会发现是某个xml文件中字符识别的问题,解决办法如下: 在pom.xml中添加以下 ...
- WP8.1学习系列(第十七章)——交互UX之输入和反馈模式
如果你将 Windows 应用商店应用设计为触摸交互,则可免费获取对触摸板.鼠标.笔和键盘交互的支持.你的用户可以从一种输入法切换到另一种,而不会丧失应用体验的感觉.将键盘插入平板电脑?没问题.你的应 ...
- Esper学习之十五:Pattern(二)
上一篇开始了新一轮语法——Pattern的讲解,一开始为大家普及了几个基础知识,其中有说到操作符.当时只是把它们都列举出来了,所以今天这篇就是专门详解这些操作符的,但是由于篇幅限制,本篇先会讲几个,剩 ...
- gerrit_bash_commands.sh
https://github.com/tomwys/gerrit-bash-commands gerrit_bash_commands.sh # Author: Tomasz Wysocki < ...