zoukankan      html  css  js  c++  java
  • 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**ik ), 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≤dn ) 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≤dn ). The second line contains nn integers a_1, a_2, dots, a_na1,a2,…,a**n ( 1 le a_i le k1≤a**ik ), 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
    ",ans);
        }
        return 0;
    }
    
  • 相关阅读:
    Spark学习之Spark调优与调试(二)
    Spark学习之Spark调优与调试(一)
    Spark学习之在集群上运行Spark
    Spark学习之编程进阶总结(二)
    Spark学习之编程进阶总结(一)
    Spark学习之数据读取与保存总结(二)
    Spark学习之数据读取与保存总结(一)
    Eclipse 出现项目没有错但是项目名称却有红色感叹号或者红叉的解决办法
    CF1284E New Year and Castle Construction
    CF559E Gerald and Path
  • 原文地址:https://www.cnblogs.com/fusiwei/p/11750638.html
Copyright © 2011-2022 走看看