标签:
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\n", res); 54 return 0; 55 }
标签:
原文地址:http://www.cnblogs.com/luomi/p/5725225.html