题解:P12404 「CZOI-R3」可爱棉羊

· · 题解

赛时只有 80 分,肯定要掉大分。实际上本题就是个贪心。

首先看最大值,我们一开始感染了 x 只,那么可以传染 t 次。我们让传染的羊都互不重复,所以最多可以感染 2 \times x \times t 只羊,由于只有 n 只羊,所以最大值为 \min\{n,2\times x\times t\}

最小值就显而易见了,除了 x=1 时肯定要多传染一只,其它的情况够可以互相重复传染,所以当 x=1 时最小值为 2,否则最小值为 \min\{n,x\}

#include<bits/stdc++.h>
using ll = long long;
using namespace std;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    ll n, t, x;
    cin >> n >> t >> x;

    cout << min(x * t * 2, n) << ' ';
    if (x > 1) cout << min(n, x);
    else cout << x + 1;
    return 0;
}