• codeforces180E_尺取法


    http://codeforces.com/problemset/problem/180/E

    题意:给你n个数 m种颜色 最多可以删k个数  问你最长连续颜色相同的序列长度是多少

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <cstdio>
     6 #include <vector>
     7 #include <ctime>
     8 #include <queue>
     9 #include <list>
    10 #include <set>
    11 #include <map>
    12 using namespace std;
    13 #define INF 0x3f3f3f3f
    14 
    15 vector <int> num[100010];
    16 int main()
    17 {
    18     int n, m, k;
    19     scanf("%d %d %d", &n, &m, &k);
    20     int x;
    21     for(int i = 1; i <= n; i++)
    22     {
    23         scanf("%d", &x);
    24         num[x].push_back(i);
    25     }
    26     int res = 1;
    27     for(int i = 1; i <= m; i++)
    28     {
    29         int te = 0, l = 0;
    30         for(int j = 1; j < num[i].size(); j++)
    31         {
    32             te += num[i][j] - num[i][j - 1] - 1;
    33             if(te > k)
    34             {
    35                 te -= num[i][j] - num[i][j - 1] - 1;
    36                 res = max(res, num[i][j - 1] - num[i][l] + 1 - te);
    37                 te += num[i][j] - num[i][j - 1] - 1;
    38                 for(int l1 = l + 1; l1 <= j; l1++){                    
    39                     te -= num[i][l1] - num[i][l1 - 1] - 1;
    40                     if(te <= k)
    41                     {
    42                         l = l1;                        
    43                         break;
    44                     }
    45                 }
    46             }
    47             else if(j == num[i].size() - 1 && te <= k)            
    48             {
    49                 res = max(res, num[i][j] - num[i][l] + 1 - te);
    50             }
    51         }
    52     }
    53     printf("%d
    ", res);
    54     return 0;
    55 }
  • 相关阅读:
    测试管理工具
    测试用例--zy
    测试计划和测试用例
    测试用例
    软件测试基础
    异步任务 ---- django-celery
    图片验证码接口
    测试作业
    数据库原理
    HTTPS原理
  • 原文地址:https://www.cnblogs.com/luomi/p/5725225.html
Copyright © 2020-2023  润新知