ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2021-04-24 11:03:17  阅读:300  来源: 互联网

标签:2050 718 int rep cin && Div 105


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有