Codeforces Round 914 (Div. 2) | JorbanS

A - Forked!

int n, m;
int a, b, x, y;
const int dx[4] = {1, 1, -1, -1};
const int dy[4] = {1, -1, 1, -1};

int solve() {
    cin >> x >> y;
    map<pii, bool> mp;
    cin >> a >> b;
    for (int i = 0; i < 4; i ++) mp[{a + dx[i] * x, b + dy[i] * y}] = true;
    for (int i = 0; i < 4; i ++) mp[{a + dx[i] * y, b + dy[i] * x}] = true;
    int res = 0;
    cin >> a >> b;
    for (int i = 0; i < 4; i ++)
        if (mp[{a + dx[i] * x, b + dy[i] * y}]) {
            res ++;
            mp[{a + dx[i] * x, b + dy[i] * y}] = false;
        }
    for (int i = 0; i < 4; i ++)
        if (mp[{a + dx[i] * y, b + dy[i] * x}]) {
            res ++;
            mp[{a + dx[i] * y, b + dy[i] * x}] = false;
        }
    return res;
}

B - Collecting Game

int n, m;
pii a[N];
ll pre[N];
int ans[N];

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i ++) cin >> a[i].aa, a[i].bb = i;
    sort(a + 1, a + n + 1);
    ll sum = 0;
    int pos = 0;
    for (int i = 1; i <= n; i ++) {
        if (pos < i) pos ++, sum += a[pos].aa;
        while (a[pos + 1].aa <= sum && pos < n) sum += a[++ pos].aa;
        ans[a[i].bb] = pos - 1;
    }
    for (int i = 1; i <= n; i ++) cout << ans[i] << ' ';
    cout << endl;
}

C - Array Game

int n, m;
ll a[N], b[N];

ll solve() {
    cin >> n >> m;
    ll res = 1e18;
    for (int i = 0; i < n; i ++) cin >> a[i], res = min(res, a[i]);
    if (m >= 3) return 0;
    int nn = 0;
    for (int i = 0; i < n; i ++) {
        for (int j = i + 1; j < n; j ++) {
            ll x = abs(a[i] - a[j]);
            res = min(res, x);
            b[nn ++] = x;
        }
    }
    if (m == 1) return res;
    sort(b, b + nn);
    for (int i = 0; i < n; i ++) {
        int l = upper_bound(b, b + nn, a[i]) - b - 1;
        int r = lower_bound(b, b + nn, a[i]) - b;
        if (l >= 0 && l < nn) res = min(res, abs(a[i] - b[l]));
        if (r < nn) res = min(res, abs(a[i] - b[r]));
    }
    return res;
}

D1 - Set To Max (Easy Version)

int n, m;
int a[N], b[N];

string solve() {
    cin >> n;
    for (int i = 0; i < n; i ++) cin >> a[i];
    for (int i = 0; i < n; i ++) cin >> b[i];
    int l = 0, r = 0;
    while (r < n) {
        while (b[r + 1] == b[l] && r + 1 < n) r ++;
        int maxx = 0;
        for (int i = l; i <= r; i ++) maxx = max(maxx, a[i]);
        if (maxx != b[l]) {
            int L = l, R = r;
            while (L - 1 >= 0 && a[L - 1] <= b[l] && b[L - 1] >= b[l] && a[L] != b[l]) L --;
            while (R + 1 < n && a[R + 1] <= b[l] && b[R + 1] >= b[l] && a[R] != b[l]) R ++;
            if (a[L] != b[l] && a[R] != b[l] || L == l && R == r) return no;
            if (L == l && a[R] != b[l] || R == r && a[L] != b[l]) return no;
        }
        r ++, l = r;
    }
    return yes;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JorbanS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值