[HIHO1051]补提交卡(枚举,贪心)

题目链接:http://hihocoder.com/problemset/problem/1051

思路:先排序,然后枚举连续的长度为m的子段,用这个段之后的第一个天数减去这个段之前的第一个天数再-1就是把这个区间全填上后的连续提交天数。

 1 /*
 2 ━━━━━┒ギリギリ♂ eye!
 3 ┓┏┓┏┓┃キリキリ♂ mind!
 4 ┛┗┛┗┛┃\○/
 5 ┓┏┓┏┓┃ /
 6 ┛┗┛┗┛┃ノ)
 7 ┓┏┓┏┓┃
 8 ┛┗┛┗┛┃
 9 ┓┏┓┏┓┃
10 ┛┗┛┗┛┃
11 ┓┏┓┏┓┃
12 ┛┗┛┗┛┃
13 ┓┏┓┏┓┃
14 ┃┃┃┃┃┃
15 ┻┻┻┻┻┻
16 */
17 #include <algorithm>
18 #include <iostream>
19 #include <iomanip>
20 #include <cstring>
21 #include <climits>
22 #include <complex>
23 #include <fstream>
24 #include <cassert>
25 #include <cstdio>
26 #include <bitset>
27 #include <vector>
28 #include <deque>
29 #include <queue>
30 #include <stack>
31 #include <ctime>
32 #include <set>
33 #include <map>
34 #include <cmath>
35 using namespace std;
36 #define fr first
37 #define sc second
38 #define cl clear
39 #define BUG puts("here!!!")
40 #define W(a) while(a--)
41 #define pb(a) push_back(a)
42 #define Rint(a) scanf("%d", &a)
43 #define Rll(a) scanf("%I64d", &a)
44 #define Rs(a) scanf("%s", a)
45 #define Cin(a) cin >> a
46 #define FRead() freopen("in", "r", stdin)
47 #define FWrite() freopen("out", "w", stdout)
48 #define Rep(i, len) for(LL i = 0; i < (len); i++)
49 #define For(i, a, len) for(LL i = (a); i < (len); i++)
50 #define Cls(a) memset((a), 0, sizeof(a))
51 #define Clr(a, x) memset((a), (x), sizeof(a))
52 #define Fuint(a) memset((a), 0x7f7f, sizeof(a))
53 #define lrt rt << 1
54 #define rrt rt << 1 | 1
55 #define pi 3.14159265359
56 #define RT return
57 #define lowbit(x) x & (-x)
58 #define onenum(x) __builtin_popcount(x)
59 typedef long long LL;
60 typedef long double LD;
61 typedef unsigned long long Uint;
62 typedef pair<LL, LL> pii;
63 typedef pair<string, LL> psi;
64 typedef map<string, LL> msi;
65 typedef vector<LL> vi;
66 typedef vector<LL> vl;
67 typedef vector<vl> vvl;
68 typedef vector<bool> vb;
69 
70 const int maxn = 110;
71 int n, m;
72 int a[maxn];
73 int G[maxn][maxn];
74 
75 int main() {
76     // FRead();
77     int T;
78     Rint(T);
79     W(T) {
80         Cls(G); Cls(a);
81         Rint(n); Rint(m);
82         For(i, 1, n+1) Rint(a[i]);
83         if(m >= n) {
84             printf("100
");
85             continue;
86         }
87         sort(a+1, a+n+1);
88         int ret = 0;
89         for(int i = 1; i <= n - m + 1; i++) {
90             int j = i + m - 1;
91             int tmp = a[j+1] - a[i-1] - 1;
92             ret = max(ret, tmp);
93         }
94         printf("%d
", ret);
95     }
96     RT 0;
97 }
原文地址:https://www.cnblogs.com/kirai/p/5572179.html