The Cow Lineup_找规律
Description
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
* 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
Sample Input
14 5
1
5
3
2
5
1
3
4
4
2
5
1
2
3
Sample Output
3
Hint
【题意】给定一串长度为n,各位上的数小于等于m的正数序列。问最短的不属于该序列子串的串长度为多少。
【思路】找规律。
前8个数字已经使1,2,3,4,5都至少出现一次。
所以前8个数字可以归为一个集合。
然后再发现后6个数字也是1,2,3,4,5都至少出现了一次,也归为一个集合。
最后的答案数是集合数+1.
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=;
const int M=;
int a[N],vis[M];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
memset(vis,,sizeof(vis));
int sum=,ans=;
for(int i=;i<=n;i++)
{
if(vis[a[i]]==&&a[i]<=m)
{
vis[a[i]]=;
sum+=vis[a[i]];
if(sum==m)
{
sum=;
memset(vis,,sizeof(vis));
ans++;
}
}
}
printf("%d\n",ans+);
}
return ;
}
The Cow Lineup_找规律的更多相关文章
- [USACO19FEB]Cow Dating——找规律
原题戳这里 题解 显然原题等价于让我们求这个式子\(\prod\limits_{i=l}^{r}(1-p_i)\sum\limits_{i=l}^{r}\frac{p_i}{1-p_i}\)的最大值是 ...
- hdu 3951 - Coin Game(找规律)
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- hdu4952 Number Transformation (找规律)
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...
- CF456B Fedya and Maths 找规律
http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. F ...
- hdu 4731 2013成都赛区网络赛 找规律
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举
- 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake
题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...
- 找规律 ZOJ3498 Javabeans
Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...
- C基础之递归(思想很重要,学会找规律)
递归思想的条件:1.函数自己调用自己 2.函数必须有一个固定的返回值(如果没有这个条件会发生死循环) ----规律很重要 简单递归题目一: 设计一个函数计算一个整数的n次方,比如2的3次方,就是8 步 ...
随机推荐
- emmet使用笔记及sublime常用快捷键
2015.10.07补: 格式化JS代码: 安装JSformat插件,选中需要格式化的JS代码,Ctrl+Alt+f 使用笔记看:http://www.w3cplus.com/tools/emmet- ...
- Merge k Sorted Lists [LeetCode]
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. S ...
- 190. Reverse Bits -- 按位反转
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- JSP 服务器响应
Response响应对象主要将JSP容器处理后的结果传回到客户端.可以通过response变量设置HTTP的状态和向客户端发送数据,如Cookie.HTTP文件头信息等. 一个典型的响应看起来就像下面 ...
- 一个简单的excel文件上传到数据库方法
因为以前项目中有用到过Excel导入,所以整理了一下,这是一个导入Excel数据到数据库的方法 注意:需要导入poi jar包 代码清单 /** * Excel 导入 * @param mapping ...
- 最新版Intel HD4000 桌面右键菜单去除方法
网上找了一圈都提示找不到指定模块,后来发现它换dll了 regsvr32 /u igfxDTCM.dll
- NSArray和NSDictionary的混合
- swift 开眼今日精选
swift 开眼今日精选 import UIKit class TodayController: UITableViewController { vararray =NSMutableArray() ...
- daemon
关于daemon,其最简单的用法是: , ) == -) ; 将上面代码放置程序中,程序执行到这一行,就会自动进入后台运行,不再与终端交互,即终端再输入的参数无效,程序的输出(比如printf等)无效 ...
- Android Phonebook编写联系人UI加载及联系人保存流程(一)
2014-01-06 17:05:11 将百度空间里的东西移过来. 本文适合ROM定制做Phonebook的童鞋看,其他人飘过即可- Phonebook添加/编辑联系人UI加载及保存联系人流程,是一系 ...