hihoCoder#1051 补提交卡

原题地址

简单贪心

首先,补提交卡应该连续使用,其次,补提交卡应该全部用掉(如果补提交卡多于未提交天数则额外处理)

所以,依次遍历未提交日期,计算:从当前位置开始,用M张补提交卡覆盖后面连续M个数字,此时的连续提交天数。

代码:

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main() {
 6     int n;
 7     int N, M;
 8     int a[128];
 9     
10     cin >> n;
11     while (n--) {
12         cin >> N >> M;
13         int res = M >= N ? 100 : 0;
14         for (int i = 0; i < N; i++)
15             cin >> a[i];
16         for (int i = 0; i <= N - M; i++) {
17             int begin = i > 0 ? a[i - 1] + 1 : 1;
18             int end = i + M < N ? a[i + M] - 1 : 100;
19             res = max(res, end - begin + 1);
20         }
21         cout << res << endl;
22     }
23     
24     return 0;
25 }
原文地址:https://www.cnblogs.com/boring09/p/4355912.html