首页 > 其他分享 >AtCoder Beginner Contest 272(A~E)

AtCoder Beginner Contest 272(A~E)

时间:2022-10-09 17:13:00浏览次数:45  
标签:AtCoder Beginner int auto back v2 272 push size

A


void solve(int Case) {
    int n;
    cin >> n;
    vector<int>a(n);
    for (auto &i : a) cin >> i;
    cout << accumulate(all(a), 0) << nline;
}

B

const int N = 550;
int d[N][N];
void solve(int Case) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int x;
        cin >> x;
        vector<int> v(x);
        for (auto &j : v) cin >> j;
        for (int j = 0; j < v.size(); j++) {
            for (int k = j + 1; k < v.size(); k++) {
                d[v[j]][v[k]] = 1;
            }
        }
    }
    bool ok = true;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            ok &= d[i][j];
        }
    }
    if (ok) cout << "Yes" << nline;
    else cout << "No" << nline;

}

C

const int N = 200010;
int a[N];
void solve(int Case) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + 1 + n);
    vector<int> v1, v2;
    for (int i = 1; i <= n; i++) {
        if (a[i] & 1) v1.push_back(a[i]);
        else v2.push_back(a[i]);
    }
    int mmax = -1;
    if (v1.size() >= 2) {
        mmax = max(mmax, v1[v1.size() - 1] + v1[v1.size() - 2]);
    }
    if (v2.size() >= 2) {
        mmax = max(mmax, v2[v2.size() - 1] + v2[v2.size() - 2]);
    }
    cout << mmax << nline;
}
 

D

using PII = pair<int, int>;
vector<PII> v;
int n, m;
bool vis[N][N];
int d[N][N];
void bfs() {
    queue<PII> q;
    q.push({1, 1});
    d[1][1] = 0;
    vis[1][1] = 1;
    while (q.size()) {
        auto [x, y] = q.front();
        q.pop();
        for (auto [dx, dy] : v) {
            int nx = x - dx, ny = y - dy;
            if (nx >= 1 and nx <= n and ny >= 1 and ny <= n) {
                if (!vis[nx][ny]) {
                    vis[nx][ny] = 1;
                    d[nx][ny] = d[x][y] + 1;
                    q.push({nx, ny});
                }
 
            }
            nx = x - dx, ny = y + dy;
            if (nx >= 1 and nx <= n and ny >= 1 and ny <= n) {
                if (!vis[nx][ny]) {
                    vis[nx][ny] = 1;
                    d[nx][ny] = d[x][y] + 1;
                    q.push({nx, ny});
                }
            }
            nx = x + dx, ny = y - dy;
            if (nx >= 1 and nx <= n and ny >= 1 and ny <= n) {
                if (!vis[nx][ny]) {
                    vis[nx][ny] = 1;
                    d[nx][ny] = d[x][y] + 1;
                    q.push({nx, ny});
                }
            }
            nx = x + dx, ny = y + dy;
            if (nx >= 1 and nx <= n and ny >= 1 and ny <= n) {
                if (!vis[nx][ny]) {
                    vis[nx][ny] = 1;
                    d[nx][ny] = d[x][y] + 1;
                    q.push({nx, ny});
                }
            }
        }
 
    }
}
void solve(int Case) {
    cin >> n >> m;
    for (int i = 1; i <= 1010; i++) {
        int x = i * i;
        if (x > m) break;
        int y = m - x;
        int c = sqrt(y);
        if (c * c == y ) {
            v.push_back({i, c});
            v.push_back({c, i});
        }
    }
    memset(d, 0x3f, sizeof d);
    bfs();
    // cout << dfs(1, 2) << nline;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
 
            int x = d[i][j];
            if (x == 0x3f3f3f3f3f3f3f3f) x = -1;
            cout << x << ' ';
        }
        cout << nline;
    }
}

E

 
const int N = 200010;
int a[N];
vector<int> v;
struct T {
    int x, t;
};
vector<T> h[N];
void solve(int Case) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        if (a[i] < 0) {
            int c = abs(a[i]) / i;
            if (c - 1 > N - 5) continue;
            h[max(0LL, c - 1)].push_back({a[i] + max(0LL, (c - 1)) * i, i});
        } else {
            h[0].push_back({a[i], i});
        }
    }
    vector<T> v;
    for (auto t : h[0]) v.push_back(t);
    for (int i = 1; i <= m; i++) {
        vector<T> cur;
        map<int, int> mp;
        int s = 0;
        for (auto &[x, y] : v) {
            x += y;
        }
        for (auto [x, y] : v) {
            mp[x]++;
        }
        while (mp[s]) s++;
        cout << s << nline;
        for (auto[x, y] : v) {
            if (x > n) continue;
            cur.push_back({x, y});
        }
        v = cur;
        for (auto t : h[i]) v.push_back(t);
    }
}
 

标签:AtCoder,Beginner,int,auto,back,v2,272,push,size
From: https://www.cnblogs.com/koto-k/p/16772830.html

相关文章

  • AtCoder Beginner Contest 272 D Root M Leaper
    RootMLeaper\(bfs\)模拟先把能走的矩阵预处理出来,然后直接跑\(bfs\)要注意各种边界#include<iostream>#include<cstdio>#include<array>#include<queue>us......
  • abc272_f Two Strings (后缀数组)
    https://atcoder.jp/contests/abc272/tasks/abc272_f将SS#TT在字符串中排序,看标号为1-n后面有多少2n+2-3n+1的标号然后就会注意题目要的是小于等于,那么要拼成SS......
  • AtCoder Beginner Contest 271
    咕咕咕咕。E-SubsequencePath最短路问题变种,Dijkstra最短路改改就行了。AC代码//Problem:E-SubsequencePath//Contest:AtCoder-KYOCERAProgrammingC......
  • AtCoder Regular Contest 149
    ARC149A-RepdigitNumber符合条件的数一共只有\(9N\)个,随便怎么做都行。ACCodeARC149B-TwoLISSum这个操作相当于我们可以将\(A\)任意排列,然后对\(B\)进行......
  • AtCoder Regular Contest 149(持续更新)
    Preface最近国庆在外面玩的有点high啊,欠了一篇AT和两篇CF没写,今天先浅浅写一下这场当时10.2号在外面玩得有点晚了,到寝室刚好比赛开始,晚饭都没吃就开干了主要是C写的太久......
  • AtCoder Regular Contest 149
    A发现所有数字都相同的数一共只有\(10^6\)种,考虑枚举每种情况,关键在于如何判断一个数\(\bmodm\)是否为\(0\)。考虑\(9\bmod8=1\),而\(99\bmod8=(9\times10+9)\b......
  • AtCoder Beginner Contest 271
    AtCoderBeginnerContest271D-FlipandAdjust一共有\(N\)张牌,每一面都写着一个整数。卡\(i(1\lei\leN)\)前面写着整数\(a_i\),后面写着整数\(b_i\)。你可......
  • AtCoder Regular Contest 137 D
    一道很好的题目,运用了很多不同的技巧。结论1:枚举变换次数\(k\),若\(A_{i}\)对答案有贡献,当且仅当\(C_{n-i+k-1}^{k-1}\equiv1\mod2\)。首先我们可以统计\(A_{p}\)对......
  • Atcoder 题目选做
    ABC257G直接考虑\(\rmKMP\)的过程。\(\rmKMP\)可以帮助我们求出\(S\)的\(border\),并找到\(T\)中每一个位置能匹配上的\(S\)的最长前缀。那么我们就可以很......
  • 【合集】AtCoder 比赛题解
    PartAABCABC266(A-Ex)ABC267(A-G)ABC268(A-D)ABC269(A-F)ABC270(D-E)ABC271(C-F)PartBARCARC148(C)......