其他分享
首页 > 其他分享> > Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)

Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)

作者:互联网

Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)

也就会写写模拟了

A - Sum of 2050

数位和

int main() {
    IOS;
    for (cin >> _; _; --_) {
        ll n, x; cin >> n;
        if (n % 2050) { cout << "-1\n"; continue; }
        x = n / 2050; n = 0;
        while (x) n += x % 10, x /= 10;
        cout << n << '\n';
    }
    return 0;
}

B - Morning Jogging

int s[105][105], a[105][105], b[105], d[105];
 
int main() {
    IOS;
    for (cin >> _; _; --_) {
        cin >> n >> m;
        rep (i, 1, n) rep(j, 1, m) cin >> a[i][j];
        rep (i, 1, n) sort(a[i] + 1, a[i] + 1 + m), b[i] = 1, d[i] = m;
        rep (j, 1, m) {
            int mi = 2e9, w = 0;
            rep (i, 1, n) if (umin(mi, a[i][b[i]])) w = i;
            rep (i, 1, n) if (i ^ w) s[j][i] = a[i][d[i]--];
            s[j][w] = a[w][b[w]++];
        }
        rep (i, 1, n) rep (j, 1, m) cout << s[j][i] << char(" \n"[j == m]);
    }
    return 0;
}

C - Fillomino 2

贪心, 要相连, 最后先平着, 平不了, 再向下

在相连的时候优先先上左走, 其次是下右

int a[505][505];
 
void dfs(int x, int y, int k, int &c) {
    if (c == 0) return;
    if (x - 1 && !a[x - 1][y]) a[x - 1][y] = k, dfs(x - 1, y, k, --c);
    if (c && y - 1 && !a[x][y - 1]) a[x][y - 1] = k, dfs(x, y - 1, k, --c);
    if (c && x + 1 <= n && !a[x + 1][y]) a[x + 1][y] = k, dfs(x + 1, y, k, --c);
    if (c && y + 1 < x && !a[x][y + 1]) a[x][y + 1] = k, dfs(x, y + 1, k, --c);
}
 
int main() {
    IOS; cin >> n;
    rep (i, 1, n) {
        cin >> a[i][i]; int c = a[i][i] - 1;
        if (c && i - 1 && !a[i][i - 1]) a[i][i - 1] = a[i][i], dfs(i, i - 1, a[i][i], --c);
        else if (c && i + 1 <= n) a[i + 1][i] = a[i][i], dfs(i + 1, i, a[i][i], --c);
        if (c) return cout << -1, 0;
    }
    rep (i, 1, n) rep(j, 1, i) cout << a[i][j] << char(" \n"[j == i]);
    return 0;
}

D - Explorer Space

int d[N][N][11], a[N][N], b[N][N];

int main() {
    IOS; cin >> n >> m >> k; 
    if (k & 1) { 
        rep (i, 1, n) rep (j, 1, m) cout << -1 << char(" \n"[j == m]);
        return 0;
    } k >>= 1;
    memset(d, 0x3f, sizeof d);
    rep (i, 1, n) rep (j, 1, m - 1) {
        cin >> a[i][j]; a[i][j] <<= 1;
        umin(d[i][j][1], a[i][j]); umin(d[i][j + 1][1], a[i][j]);
    }
    rep (i, 1, n - 1) rep (j, 1, m) {
        cin >> b[i][j]; b[i][j] <<= 1;
        umin(d[i][j][1], b[i][j]); umin(d[i + 1][j][1], b[i][j]);
    }
    rep (t, 2, k) rep (i, 1, n) rep (j, 1, m) {
        if (i - 1) umin(d[i][j][t], d[i - 1][j][t - 1] + b[i - 1][j]);
        if (j - 1) umin(d[i][j][t], d[i][j - 1][t - 1] + a[i][j - 1]);
        if (i < n) umin(d[i][j][t], d[i + 1][j][t - 1] + b[i][j]);
        if (j < m) umin(d[i][j][t], d[i][j + 1][t - 1] + a[i][j]);
        umin(d[i][j][t], d[i][j][t - 1] + d[i][j][1]);
    }
    rep (i, 1, n) rep (j, 1, m) cout << d[i][j][k] << char(" \n"[j == m]);
    return 0;
}

标签:2050,718,int,rep,cin,&&,Div,105
来源: https://www.cnblogs.com/2aptx4869/p/14696380.html