CF1225B1 TV Subscriptions (Easy Version)
CF1225B1 TV Subscriptions (Easy Version)
题目描述
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the kk TV shows. You know the schedule for the next nn days: a sequence of integers a_1, a_2, \dots, a_na1,a2,…,a**n ( 1 \le a_i \le k1≤a**i≤k ), where a_ia**i is the show, the episode of which will be shown in ii -th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows dd ( 1 \le d \le n1≤d≤n ) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of dd consecutive days in which all episodes belong to the purchased shows.
输入格式
The first line contains an integer tt ( 1 \le t \le 1001≤t≤100 ) — the number of test cases in the input. Then tt test case descriptions follow.
The first line of each test case contains three integers n, kn,k and dd ( 1 \le n \le 1001≤n≤100 , 1 \le k \le 1001≤k≤100 , 1 \le d \le n1≤d≤n ). The second line contains nn integers a_1, a_2, \dots, a_na1,a2,…,a**n ( 1 \le a_i \le k1≤a**i≤k ), where a_ia**i is the show that is broadcasted on the ii -th day.
It is guaranteed that the sum of the values of nn for all test cases in the input does not exceed 100100 .
输出格式
Print tt integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for dd consecutive days. Please note that it is permissible that you will be able to watch more than dd days in a row.
输入输出样例
输入 #1复制
输出 #1复制
说明/提示
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show 11 and on show 22 . So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows 3,5,7,8,93,5,7,8,9 , and you will be able to watch shows for the last eight days.
题解:
题目翻译:
有一个长度为\(n\)的数列,里面有\(k\)种不同的颜色(准确地说,是\(1-k\)的任意几种颜色),请问一个大小为\(d\)的滑动窗口最少能包含多少种不同的颜色。
题解:
一道滑动窗口的题。因为是简单版数据都在100以内,所以我们考虑用暴力水过(正解请看我困难版的题解)。
暴力思路比较好想。就是for循环枚举区间,然后对颜色进行标记统计即可。
注意一些细节:
因为是多组数据,所以每组数据开始跑之前一定要清零。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=110;
int n,k,d,ans,tmp;
int a[maxn];
bool v[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ans=1<<30;
scanf("%d%d%d",&n,&k,&d);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
memset(v,0,sizeof(v));
tmp=0;
if(i+d-1==n+1)
break;
for(int j=i;j<=i+d-1;j++)
{
if(!v[a[j]])
tmp++;
v[a[j]]=1;
}
ans=min(ans,tmp);
}
printf("%d\n",ans);
}
return 0;
}
CF1225B1 TV Subscriptions (Easy Version)的更多相关文章
- CF1225B2 TV Subscriptions (Hard Version)
CF1225B2 TV Subscriptions (Hard Version) 洛谷评测传送门 题目描述 The only difference between easy and hard vers ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)
链接: https://codeforces.com/contest/1247/problem/B2 题意: The only difference between easy and hard ver ...
- B2 - TV Subscriptions (Hard Version)
题目连接:https://codeforces.com/contest/1247/problem/B2 题解:双指针,,一个头,一个尾,头部进入,尾部退出,一开始先记录1到k,并记录每个数字出现的次数 ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B. TV Subscriptions 尺取法
B2. TV Subscriptions (Hard Version) The only difference between easy and hard versions is constraint ...
- Ping-Pong (Easy Version)(DFS)
B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...
- ZOJ 3868 - Earthstone: Easy Version
3868 - Earthstone: Easy Version Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld ...
- Codeforces 1077F1 Pictures with Kittens (easy version)(DP)
题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...
- UVA12569-Planning mobile robot on Tree (EASY Version)(BFS+状态压缩)
Problem UVA12569-Planning mobile robot on Tree (EASY Version) Accept:138 Submit:686 Time Limit: 300 ...
- Coffee and Coursework (Easy version)
Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabyte ...
随机推荐
- 调用百度语音AI实现语音的识别和合成
#coding:utf-8 ## 先去ffmpeg官网下载(https://ffmpeg.zeranoe.com/builds/),好了之后解压缩,配一下环境变量 ## 打开cmd,运行命令,安装如下 ...
- BZOJ1369/LG4395 「BOI2003」Gem 树形DP
问题描述 LG4395 BZOJ1369 题解 发现对于结点 \(x\) ,其父亲,自己,和所有的孩子权值不同,共 \(3\) 类,从贪心的角度考虑,肯定是填 \(1,2,3\) 这三种. 于是套路树 ...
- 设计模式-State(行为模式)-很好的实现了对象的状态逻辑与动作实现的分类,状态逻辑在State的派生类实现,动作可以放在Context类中实现。
以下代码来源: 设计模式精解-GoF 23种设计模式解析附C++实现源码 //Context.h #pragma once class State; class Context { public: C ...
- 大学ACM学习笔记
高斯消元 该来的总会来的系列 int gauss() { for(int i=1;i<=n;i++)//按照列来枚举,当前之前i-1列全消完了 { int k=i; for(int j=i+1; ...
- Please make sure you have the correct access rights and the repository exists.
参考:https://blog.csdn.net/jingtingfengguo/article/details/51892864,感谢老哥. 从码云克隆项目到新的服务器上,报错: Please ma ...
- Kettle在windows上安装
Kettle是一款国外开源的ETL工具,纯java编写,可以在Windows.Linux.Unix上运行,数据抽取高效稳定. 因为有个日常提数,工作日每天都要从数据库中提取数据,转换为excel,再以 ...
- 使用Redis实现最近N条数据的决策
前言 很多时候,我们会根据用户最近一段时间的行为,做出一些相应的策略,从而改变系统的运动轨迹. 举个简单的例子来说明一下: 假设A公司现在有两个合作伙伴(B和C),B和C都是提供天气数据的,现在A公司 ...
- MySQL for OPS 09:MHA + Atlas 实现读写分离高可用
写在前面的话 前面做了 MHA 高可用,但是存在这样一个问题,我们花了 4 台机器,但是最终被利用起来的也就一台,主库.这样硬件利用率才 25%,这意味着除非发生故障,不然其他几台机器都是摆设.明显的 ...
- Python中字符的编码与解码
1 文本和字节序列 我们都知道字符串,就是由一些字符组成的序列构成串,那么字符又是什么呢?计算机只能识别二进制的东西,那么计算机又为什么会显示我们的汉字,或者是某个字母呢? 由于最早发明使用计算机是美 ...
- Java学习笔记 DbUtils数据库查询和log4j日志输出 使用
DbUtils使用 QueryRunner DbUtils中定义了一个数据库操作类QueryRunner,所有的数据库操作CRUD都是通过此类来完成. 此类是线程安全的 方法名 对应sql语句 exc ...