Codeforces Round #637 (Div. 1) – Thanks, Ivan Belonogov! 题解

作者: xht37 分类: 题解 发布时间: 2020-04-24 14:45

点击数:50

Codeforces Round #637 (Div. 1) – Thanks, Ivan Belonogov!
Update:哈哈哈它 Unrated 了,爷的青春回来了。

Nastya and Strange Generator

垃圾题,模拟。

有病吧题面写这么长。

const int N = 1e5 + 7;
int n, p[N];
bool v[N];

inline void solve() {
    rd(n), rda(p, n);
    for (int i = 1; i <= n; i++) v[i] = 0;
    for (int i = 1, k = -1; i <= n; i++) {
        if (!~k || v[k+1] || k == n) k = p[i];
        else if (p[i] != k + 1) return prints("No"), void();
        else ++k;
        v[p[i]] = 1;
    }
    prints("Yes");
}

int main() {
    int T;
    rd(T);
    while (T--) solve();
    return 0;
}

Nastya and Scoreboard

垃圾题,DP 一下就行了。

有病吧都 0202 年了还出火柴摆数字。

const int N = 2e3 + 7;
const string str[] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"};
int n, k, f[N][N], g[N][N];
string s[N];

inline int calc(string a, string b) {
    int ret = 0;
    for (int i = 0; i < 7; i++)
        if (a[i] == '1' && b[i] == '0') return -1;
        else ret += b[i] - a[i];
    return ret;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> s[i];
    reverse(s + 1, s + n + 1);
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= k; j++)
            f[i][j] = -1;
    f[0][k] = 0;
    for (int i = 0; i < n; i++)
        for (int t = 0; t < 10; t++) {
            int ret = calc(s[i+1], str[t]);
            for (int j = k; ~j; j--)
                if (~f[i][j] && ~ret && ret <= j)
                        f[i+1][j-ret] = t, g[i+1][j-ret] = ret;
        }
    if (!~f[n][0]) return cout << -1 << endl, 0;
    string ans;
    for (int i = n, j = 0; i; i--)
        ans += f[i][j] + '0', j += g[i][j];
    cout << ans << endl;
    return 0;
}

Nastya and Unexpected Guest

01 bfs,稍微有点意思。

有病吧题面里特么还有心理活动描写。

const int N = 1e4 + 7, M = 1e3 + 7, inf = 1e9;
const ll infll = 1e18;
int n, m, a[N], g, r, f[N][M];
deque<pi> q;

int main() {
    rd(n, m), rda(a, m), rd(g, r);
    sort(a + 1, a + m + 1);
    for (int i = 1; i <= m; i++)
        for (int j = 0; j < g; j++)
            f[i][j] = inf;
    f[1][0] = 0, q.pb(mp(1, 0));
    while (q.size()) {
        int x = q[0].fi, t = q[0].se;
        q.pop_front();
        if (x > 1) {
            int k = t + a[x] - a[x-1];
            if (k < g && f[x-1][k] > f[x][t])
                f[x-1][k] = f[x][t], q.push_front(mp(x - 1, k));
            if (k == g && f[x-1][0] > f[x][t] + 1)
                f[x-1][0] = f[x][t] + 1, q.pb(mp(x - 1, 0));
        }
        if (x < m) {
            int k = t + a[x+1] - a[x];
            if (k < g && f[x+1][k] > f[x][t])
                f[x+1][k] = f[x][t], q.push_front(mp(x + 1, k));
            if (k == g && f[x+1][0] > f[x][t] + 1)
                f[x+1][0] = f[x][t] + 1, q.pb(mp(x + 1, 0));
        }
    }
    ll ans = infll;
    for (int i = 1; i <= m; i++)
        if (a[i] + g >= n && f[i][0] != inf)
            ans = min(ans, 1ll * f[i][0] * (g + r) + n - a[i]);
    print(ans == infll ? -1 : ans);
    return 0;
}

Nastya and Time Machine

构造题,比较有意思。

猜到答案是度数最大值就好做了。

const int N = 1e5 + 7;
int n, d[N], D;
vi e[N];
vector<pi> ans;

void dfs(int x, int f, int t) {
    int k = t;
    ans.pb(mp(x, t));
    for (int y : e[x])
        if (y != f) {
            if (t == D) ans.pb(mp(x, t = D - d[x]));
            dfs(y, x, ++t);
            ans.pb(mp(x, t));
        }
    if (f && t != k - 1) ans.pb(mp(x, t = k - 1));
}

int main() {
    rd(n);
    for (int i = 1, x, y; i < n; i++)
        rd(x), rd(y), e[x].pb(y), e[y].pb(x), ++d[x], ++d[y];
    D = *max_element(d + 1, d + n + 1);
    dfs(1, 0, 0);
    print(ans.size());
    for (pi o : ans) print(o.fi, o.se);
    return 0;
}

Nastya and Bees

假题,shit。

Nastya and CBS

题目太神仙了,先咕咕咕着。

发表评论

电子邮件地址不会被公开。 必填项已用*标注