A 喝饮料

  • 看似很麻烦,但只有一步
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    int n, x, y, k, ans;
    signed main() {
    IOS;
    cin >> n >> x >> y;
    k = n / x;
    ans += n / x;
    while (k >= y) {
    ans += k / y;
    k = k % y + k / y;
    }
    if (k + 1 == y) ans++;
    cout << ans << endl;

    return 0;
    }

B. 非零位

  • 只要取一个大小差不多的十的倍数就好了
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    const ll mod = 100000;

    signed main() {
    IOS;
    ll n, ans = 1;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
    ans = ans * i;
    while (ans % 10 == 0) ans /= 10;
    ans %= mod;
    }
    cout << ans % 10 << endl;


    return 0;
    }

C. 排队充饭卡

  • 从大到小去谈心就好了
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    priority_queue<int> q;
    signed main() {
    IOS;
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    q.push(x);
    }
    while (!q.empty()) {
    int x = q.top();
    q.pop();
    if (x < ans) {
    continue;
    }
    ans = ans + 1;
    }
    cout << ans << endl;

    return 0;
    }

D. 等公交

  • 二分的去贪心就好了
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    #define MAX 100005
    int n, m, c;
    int a[MAX];
    bool check(int x) {
    int cnt = 0, lst = -1, num = 0;
    for (int i = 1; i <= n; i++) {
    if (lst < a[i] || num == c) {
    num = 0;
    cnt++;
    lst = a[i] + x;
    }
    num++;
    }
    return cnt <= m;
    }
    signed main() {
    IOS;
    cin >> n >> m >> c;
    for (int i = 1; i <= n; i++) {
    cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    int l = 1, r = 1e9, ans = -1;
    while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
    ans = mid;
    r = mid - 1;
    } else {
    l = mid + 1;
    }
    }
    cout << ans << endl;

    return 0;
    }

E. 因数个数

F. 趟水

  • 用并查集去维护就好了
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    struct node {
    int tp, d, s, uid;
    node(int tp, int d, int s, int uid) : tp(tp), d(d), s(s), uid(uid) {}
    friend bool operator<(node A, node B) {
    if (A.d == B.d)
    return A.tp < B.tp;
    return A.d < B.d;
    }
    };
    #define MAX 1000005
    int a[MAX], fa[MAX], sz[MAX], ans[MAX];
    int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
    }
    void merge(int x, int y) {
    int fx = find(x), fy = find(y);
    if (fx == fy)
    return;
    fa[fy] = fx;
    sz[fx] += sz[fy];
    }
    priority_queue<node> q;
    int n, m;
    signed main() {
    IOS;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
    int d;
    sz[i] = 1;
    fa[i] = i;
    cin >> d;
    q.push(node(1, d, i, 0));
    }
    for (int i = 1; i <= m; i++) {
    int d, s;
    cin >> d >> s;
    q.push(node(2, d, s, i));
    }
    int mx = 0;
    while (!q.empty()) {
    node tmp = q.top();
    q.pop();
    int tp = tmp.tp, d = tmp.d, s = tmp.s, uid = tmp.uid;
    if (tp == 1) {
    a[s] = 1;
    if (a[s - 1]) {
    merge(s, s - 1);
    }
    if (a[s + 1]) {
    merge(s, s + 1);
    }
    mx = max(mx, sz[find(s)]);
    //cout << sz[find(s)] << endl;
    //cout << d << ' ' << s << ' ' << mx << endl;
    } else {
    //cout << uid << ' ' << s << ' ' << mx << endl;
    if (s > mx) {
    ans[uid] = 1;
    } else {
    ans[uid] = 0;
    }
    }
    }
    for (int i = 1; i <= m; i++) {
    cout << ans[i] << endl;
    }
    return 0;
    }

G. 没有找零

  • 只要提前预处理出从哪到哪就好了
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    #define MAX 100005
    const int M = (1 << 17);
    int n, k, a[MAX], d[MAX], q[20][MAX], DP[M];
    signed main()
    {
    IOS;
    cin >> k >> n;
    for (int i = 1; i <= k; i++)
    {
    cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
    cin >> d[i];
    }
    for (int i = 1; i <= k; i++)
    {
    int res = 0;
    for (int l = 1, r = 0; l <= n; res -= d[l++])
    {
    while (r < n && res + d[r + 1] <= a[i])
    {
    res += d[++r];
    }
    q[i][l] = r;
    //cout << q[i][l] << ' ';
    }
    //cout << endl;
    }
    int ans = 0;
    for (int S = 0; S < (1 << k); S++)
    {
    int res = 0;
    for (int i = 1; i <= k; i++)
    {
    if ((S >> (i - 1)) & 1)
    continue;
    res += a[i];
    DP[S | (1 << (i - 1))] = max(DP[S | (1 << (i - 1))], q[i][DP[S] + 1]);
    }
    if (DP[S] == n)
    {
    ans = max(ans, res);
    }
    // cout << (ans ? ans : -1) << endl;
    }
    cout << (ans ? ans : -1) << endl;

    return 0;
    }