M-客观的校长 BIT新生赛题目 —— 贪心*

M-客观的校长 BIT新生赛题目 —— 贪心*,第1张

M-客观的校长 BIT新生赛题目 —— 贪心*

M-客观的校长

题意中文题 思路:

 

// Decline is inevitable,
// Romance will last forever.
#include 
#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector
#define endl 'n'
#define int long long
using namespace std;
const int P = 1e9 + 7;
const int maxn = 5e3 + 10;
const int maxm = 2e6 + 10;
const int INF = 0x3f3f3f3f;
template T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template T lcm(T a, T b) { return a / gcd(a, b) * b; }
int n, k;
void solve() {
    cin >> n >> k;
    string s;
    cin >> s;
    s = ' ' + s;
    int maxx = 0;
    for(int i = 1; i <= n; i++) {
        if(s[i] == '0') continue;
        for(int j = i-1; j >= i - k; j--) {
            if(j < 1) break;
            if(s[j] == '1') {
                maxx++;
                break;
            }
        }
    }
    int minn = 0;
    int pre = -1;
    int cnt = 0;
    for(int i = 1;i <= n; i++) {
        if(s[i] == '1')
            cnt++;
    }
    for(int i = 1; i <= n; i++) {
        if(s[i] == '1') {
            pre = i;
            minn++;
            break;
        }
    }
    int tmp = pre;
    for(int i = tmp + 1; i <= n; i++) {
        if(s[i] == '1' && i-k>pre) {
            pre = i;
            minn++;
        }
    }
    minn = cnt - minn;
    cout << minn << ' ' << maxx << 'n';
}
signed main() {
//    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//    int T; cin >> T;while(T--)
    solve();
    return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3970408.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-21
下一篇 2022-10-21

发表评论

登录后才能评论

评论列表(0条)

保存