• Ice cream samples Gym


    题目:题目链接

    思路:比赛中读错了题,题目要求选一个连续区间,却读成了随便选取几个柜台,英语要好好学啊,读懂题就很简单了,扫一遍就出结果了

    AC代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <cstring>
     7 #include <vector>
     8 #include <string>
     9 #include <queue>
    10 #include <map>
    11 #include <set>
    12 
    13 #define FRER() freopen("in.txt", "r", stdin);
    14 #define INF 0x3f3f3f3f
    15 
    16 using namespace std;
    17 
    18 const int maxn = 1000000 + 5;
    19 
    20 vector<int> stand[maxn << 1];
    21 
    22 int brand[maxn], N, K;
    23 
    24 void init() {
    25     for(int i = 0; i < (N << 1); ++i) 
    26         stand[i].clear();
    27     memset(brand, 0, sizeof(brand));
    28 }
    29 
    30 int solve() {
    31     int st = 0, ed = 0, ans = INF, k = 0, now = 0;
    32     while(ed < (N << 1)) {
    33         for(int i = 0; i < stand[ed].size(); ++i) {
    34             ++now;
    35             if(brand[stand[ed][i]] == 0)
    36                 ++k;
    37             ++brand[stand[ed][i]];
    38         }
    39         ++ed;
    40         while(k == K && st < ed) {
    41             ans = min(ans, now);
    42             for(int i = 0; i < stand[st].size(); ++i) {
    43                 --now;
    44                 --brand[stand[st][i]];
    45                 if(brand[stand[st][i]] == 0)
    46                     --k;
    47             }
    48             ++st;
    49         }
    50     }
    51     return ans == INF ? -1 : ans;
    52 }
    53 
    54 int main()
    55 {
    56     //FRER()
    57     while(~scanf("%d %d", &N, &K)) {
    58         init();
    59         int n, num;
    60         for(int i = 0; i < N; ++i) {
    61             scanf("%d", &n);
    62             for(int j = 0; j < n; ++j) {
    63                 scanf("%d", &num);
    64                 stand[i].push_back(num);
    65                 stand[i + N].push_back(num);
    66             }
    67         }
    68         printf("%d
    ", solve());
    69     }
    70     return 0;
    71 }
  • 相关阅读:
    检测c/c++中内存泄露
    在一个集合S中寻找最大的C使A+B=C且A,B,C均在集合当中
    《为学》
    U盘windows无法格式化的解决办法
    java.lang.AbstractMethodError: oracle.jdbc.driver...解决方法
    sqlplus连接远程Oracle
    oracle字符集导致的乱码问题
    大端与小端存储模式详解
    《劝学》原文
    《报任安书》司马迁
  • 原文地址:https://www.cnblogs.com/fan-jiaming/p/9833770.html
Copyright © 2020-2023  润新知