码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 660 C. Hard Process (尺取)

时间:2016-08-15 14:32:52      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:http://codeforces.com/problemset/problem/660/C

尺取法

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     static int num[int(3e5 + 5)];
 6     int n, k;
 7     scanf("%d %d", &n, &k);
 8     for(int i = 1; i <= n; ++i) {
 9         scanf("%d", num + i);
10     }
11     int l = 1, res = 0, cnt = 0, flagl = 0, flagr = -1;
12     for(int i = 1; i <= n; ++i) {
13         if(num[i]) {
14             if(i - l + 1 > res) {
15                 res = i - l + 1, flagl = l, flagr = i;
16             }
17         } else {
18             cnt++;
19             while(cnt > k && l <= i) {
20                 if(!num[l++])
21                     --cnt;
22             }
23             if(i - l + 1 > res) {
24                 res = i - l + 1, flagl = l, flagr = i;
25             }
26         }
27     }
28     for(int i = flagl; i <= flagr; ++i)
29         num[i] |= 1;
30     printf("%d\n", res);
31     for(int i = 1; i <= n; ++i) {
32         printf("%d%c", num[i], i == n ? \n:  );
33     }
34     return 0;
35 }

 

Codeforces 660 C. Hard Process (尺取)

标签:

原文地址:http://www.cnblogs.com/Recoder/p/5772591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!