hihocoder1051 补提交卡(贪心)
生活随笔
收集整理的這篇文章主要介紹了
hihocoder1051 补提交卡(贪心)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 }?
轉載于:https://www.cnblogs.com/Surprisezang/p/8672782.html
總結
以上是生活随笔為你收集整理的hihocoder1051 补提交卡(贪心)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: golang 单元测试
- 下一篇: 模拟一次CSRF(跨站请求伪造)例子,适