2022 ICPC 南京站

2022 ICPC 南京

三题 铜
第一块 ICPC 牌子
用了两个小时就结束了,后面三小时 D和M一起开 非常可惜一题都没过,D题我们用了主席树加二分 复杂度是 n l o g n 2 nlogn^2 nlogn2 一直 t 可能这个复杂度就是过不了的,M题是一道计算几何 ,这道题一直是我其他两个队友在写 ,好像最后题解出来说和我们的想法差不太多,最后三题拿下铜牌~

在这里插入图片描述

A

袋鼠题~这道题容易想到 先模拟一遍哪些会因为离开边界而离开地图,这样之后会得到一个矩形,通过这个矩形我们再模拟一遍排列,就可以发现只需要对这个区间进行二维差分,最后在一般二维前缀和就可以解决了,最后判断一遍每个格子是否等于k

#include<bits/stdc++.h>

using namespace std;

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> mp(n+10, vector<int>(m+10));
    vector<vector<int>> vis(n+10, vector<int>(m+10));
    string s;
    cin >> s;
    int L = 1, R = m;
    int U = 1, D = n;
    int curL = 1, curR = m;
    int curU = 1, curD = n;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'L') {
            curL++, curR++;
        } else if (s[i] == 'R') {
            curL--; curR--;
        } else if (s[i] == 'U') {
            curU++; curD++;
        } else {
            curU--; curD--;
        }
        L = max(curL, L);
        R = min(curR, R);
        U = max(curU, U);
        D = min(curD, D);
    }
    if (U > D || L > R) {
        if (k == 0) cout << n * m << '\n';
        else cout << 0 << '\n';
        return;
    }
    int xa = U, ya = L;
    int xb = D, yb = R;
    auto add = [&](int x1, int y1, int x2, int y2) {
        if (vis[x1][y1]) return;
        vis[x1][y1] = 1;
        mp[x1][y1]++;
        mp[x2+1][y1]--;
        mp[x1][y2+1]--;
        mp[x2+1][y2+1]++;
    };
    add(xa, ya, xb, yb);
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'L') {
            ya--; yb--;
        } else if (s[i] == 'R') {
            ya++; yb++;
        } else if (s[i] == 'U') {
            xa--; xb--;
        } else {
            xa++; xb++;
        }
        add(xa, ya, xb, yb);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            mp[i][j] += mp[i-1][j] + mp[i][j-1] - mp[i-1][j-1];
            //cout << mp[i][j] << ' ';
        }
       // cout << '\n';
    }
    int cnt = (D - U + 1) * (R - L + 1);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (cnt - mp[i][j] == k) ans++;
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);    
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}

G

贪心策略,能选合并就合并,不能合并就选择加一只。
这里我们用了二分,直接二分最多需要多少次合并

#include<bits/stdc++.h>

using namespace std;

void solve() {
    int n;
    cin >> n;
    int x = 1, y = 1;
    vector<int> events(n);
    for (int i = 0; i < n; i++) cin >> events[i];
    auto check = [&](int pos, bool ans) -> bool {
        int x = 1, y = 1;
        for (int i = 0; i < n; i++) {
            int op = events[i];
            if (op == 0) {
                if (pos <= i) op = -1;
                else op = 1;
            }
            if (op == -1) {
                if (y < 2) return false;
                y--;
            } else {
                x++; y++;
            } 
        }
        if (ans) {
            int g = __gcd(x, y);
            x /= g; y /= g;
            cout << x << ' ' << y << '\n';
        }
        return true;
    };
    int ans = n;
    int l = 0, r = n-1;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (check(mid, false)) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    if (!check(ans, true)) cout << -1 << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);    
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}

I

签到~

#include<bits/stdc++.h>

using namespace std;

void solve() {
    string s;
    cin >> s;
    vector<int> cnt(26);
    for (int i = 0; i < s.length(); i++) cnt[s[i] - 'a']++;
    sort(cnt.begin(), cnt.end());
    cout << s.length() - cnt.back() << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);    
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值