http://hihocoder.com/problemset/problem/1051
一开始dfs暴搜超时
这题关键在于理解到,肯定是补连续的几天。所以说写贪心之前要好好想想,怎么贪。
1 //补题卡肯定是连续使用的 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 #include<cstdlib> 7 #include<cmath> 8 #include<vector> 9 #include<stack> 10 #include<queue> 11 #define lson l, m, rt<<1 12 #define rson m+1, r, rt<<1|1 13 #define IO ios::sync_with_stdio(false);cin.tie(0); 14 #define INF 0x3f3f3f3f 15 #define MAXN 100010 16 const int MOD=1e9+7; 17 typedef long long ll; 18 using namespace std; 19 int t, n, m, a[110], memo[110]; 20 int k, maxm = -INF; 21 int main() 22 { 23 IO; 24 cin >> t; 25 while(t--){ 26 maxm = -INF; 27 memset(memo, 0, sizeof(memo)); 28 cin >> n >> m; 29 for(int i = 0; i < n; i++){ 30 cin >> a[i]; 31 memo[a[i]] = 1; 32 } 33 if(m >= n){ 34 cout << "100" << endl; 35 } 36 else { 37 for(int i = 0; i < n-m+1; i++){//起点 38 int j = i+m;//连续消掉的下一个 39 if(i == 0){ 40 maxm = max(maxm, a[j]-1); 41 } 42 else if(j == n){ 43 maxm = max(maxm, 100-a[i]); 44 } 45 else{ 46 maxm = max(a[j]-a[i-1]-1, maxm); 47 } 48 } 49 cout << maxm << endl; 50 } 51 } 52 return 0; 53 }