ICPC 2019-2020 North-Western Russia Regional Contest | JorbanS

A - Accurate Movement

#include <iostream>

using namespace std;
#define FastIO cin.tie(nullptr) -> sync_with_stdio(false);

int solve() {
    int a, b, n; cin >> a >> b >> n;
    int dx = b - a;
    int A = (n - a + dx - 1) / dx;
    int B = (n - b + dx - 1) / dx;
    return A + B;
}

int main() {
    FastIO
    cout << solve() << endl;
    return 0;
}

E - Equidistant

#include <iostream>
#include <vector>
#include <queue>

using namespace std;
#define FastIO cin.tie(nullptr) -> sync_with_stdio(false);
#define Cases int __; cin >> __; for (int _ = 1; _ <= __; _ ++)
const string yes = "YES";
const string no = "NO";

typedef long long ll;
const int N = 2e5 + 2;
int n, m;
int deg[N];
vector<vector<int>> e(N);
vector<int> eee;
bool del[N], used[N], vis[N];
int dis[N];

int d1[N], d2[N], p1[N], up[N];

int dfs_d(int u, int fa = 0) {
    d1[u] = d2[u] = 0;
    for (auto v : e[u]) {
        if (v == fa || del[v]) continue;
        int d = dfs_d(v, u) + 1;
        if (d >= d1[u]) d2[u] = d1[u], d1[u] = d, p1[u] = v;
        else if (d > d2[u]) d2[u] = d;
    }
    return d1[u];
}

void dfs_u(int u, int fa = 0) {
    for (auto v : e[u]) {
        if (v == fa || del[v]) continue;
        if (v == p1[u]) up[v] = max(up[u], d2[u]) + 1;
        else up[v] = max(up[u], d1[u]) + 1;
        dfs_u(v, u);
    }
}

int main() {
    FastIO
    cin >> n >> m;
    for (int i = 1; i < n; i ++) {
        int u, v; cin >> u >> v;
        e[u].push_back(v), e[v].push_back(u);
        deg[u] ++, deg[v] ++;
    }
    for (int i = 1; i <= m; i ++) {
        int x; cin >> x;
        used[x] = true;
        eee.push_back(x);
    }
    queue<int> q;
    for (int i = 1; i <= n; i ++)
        if (deg[i] == 1 && !used[i]) q.push(i);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        del[u] = true;
        for (auto v : e[u]) {
            if (-- deg[v] == 1 && !used[v]) q.push(v);
        }
    }
    int st;
    for (int i = 1; i <= n; i ++)
        if (!del[i]) st = i;
    dfs_d(st);
    dfs_u(st);
    vector<int> ans;
    int minn = n;
    for (int i = 1; i <= n; i ++) {
        if (del[i]) continue;
        int l = max(d1[i], up[i]);
        if (l < minn) minn = l, ans.clear(), ans.push_back(i);
        else if (l == minn) ans.push_back(i);
    }
    for (auto i : ans) {
        for (int i = 1; i <= n; i ++) vis[i] = false;
        queue<int> q;
        q.push(i);
        dis[i] = 0;
        vis[i] = true;
        bool ok = true;
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (auto v : e[u]) {
                if (!del[v] && !vis[v]) {
                    vis[v] = true;
                    q.push(v);
                    dis[v] = dis[u] + 1;
                }
            }
        }
        for (int i = 1; i < eee.size(); i ++)
            if (dis[eee[i - 1]] != dis[eee[i]]) {
                ok = false;
                break;
            }
        if (ok) {
            cout << yes << endl << i << endl;
            return 0;
        }
    }
    cout << no << endl;
    return 0;
}

I - Ideal Pyramid

#include <iostream>

using namespace std;
#define FastIO cin.tie(nullptr) -> sync_with_stdio(false);
const int N = 1e3 + 2;
int n;
int x[N], y[N], z[N];

struct Point {
    int x, y;
    Point(int x, int y): x(x), y(y) {}
};

int main() {
    FastIO
    cin >> n;
    for (int i = 0; i < n; i ++) cin >> x[i] >> y[i] >> z[i];
    int c1 = -1e9, c2 = 1e9, c3 = -1e9, c4 = 1e9;
    for (int i = 0; i < n; i ++) {
        // x - z + c1 >= 0, c1 >= z - x
        c1 = max(c1, z[i] - x[i]);
        // x + z + c2 >= 0, c2 >= -z - x
        c2 = min(c2, -z[i] - x[i]);
        // y - z + c3 >= 0, c3 >= z - y
        c3 = max(c3, z[i] - y[i]);
        // y + z + c4 >= 0, c4 >= -z - y
        c4 = min(c4, -z[i] - y[i]);
    }
    Point A(-c1, -c3), B(-c2, -c3), C(-c2, -c4), D(-c1, -c4);
    int ab = B.x - A.x, bc = C.y - B.y;
    if (ab & 1) ab ++;
    if (bc & 1) bc ++;
    int x, y, z;
    int l = max(ab, bc);
    z = l / 2;
    x = A.x + z, y = A.y + z;
    cout << x << ' ' << y << ' ' << z << endl;
    return 0;
}

M - Managing Difficulties

#include <iostream>
#include <unordered_map>

using namespace std;
#define FastIO cin.tie(nullptr) -> sync_with_stdio(false);
#define Cases int __; cin >> __; for (int _ = 1; _ <= __; _ ++)
#define endl '\n'

typedef long long ll;
const int N = 2e5 + 2;
int n, m;

int a[N];

ll solve() {
    cin >> n;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    ll res = 0;
    unordered_map<int, int> mp;
    for (int j = 1; j < n; j ++) {
        for (int i = j + 1; i <= n; i ++)
            res += mp[2 * a[j] - a[i]];
        mp[a[j]] ++;
    }
    return res;
}

int main() {
    FastIO
    Cases
    cout << solve() << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

JorbanS

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

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

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

打赏作者

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

抵扣说明:

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

余额充值