ABC370 题解

A - Raise Both Hands Easy B - Binary Alchemy 简单模拟 #include <bits/stdc++.h> #define int long long #define inf 0x7fffffffffffffff using namespace std;

A - Raise Both Hands

Easy

B - Binary Alchemy

简单模拟

#include <bits/stdc++.h>
#define int long long
#define inf 0x7fffffffffffffff
using namespace std;

// #define cin is
// #define cout os
// ifstream is(".in", ios::in);
// ofstream os(".out", ios::out);

int n, a[111][111], now=1;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for (int i = 1;i <= n;++i) {
        for (int j = 1;j <= i;++j) {
            cin >> a[i][j];
        }
    }
    for (int i = 1;i <= n;++i) {
        if (now < i) {
            now = a[i][now];
        } else {
            now = a[now][i];
        }
    }
    cout << now << endl;
    return 0;
}

C - Word Ladder

要使最后产生的序列的字典序最小,则需要尽量保留字符串中靠前的、字典序小的字母,也就是说我们需要优先更改 S 中大于 T 中对应位置的字符。

#include <bits/stdc++.h>
#define int long long
#define inf 0x7fffffffffffffff
using namespace std;

// #define cin is
// #define cout os
// ifstream is("c.in", ios::in);
// ofstream os("c.out", ios::out);

string s, t;
set<int> diff, del;
vector<string> v;

signed main( ) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> s >> t;
    for (size_t i = 0;i < s.size( );++i) {
        if (s[i] != t[i]) {
            diff.insert(i);
        }
    }
    cout << diff.size( ) << endl;
    for (auto x : diff) {
        if (s[x] > t[x]) {
            s[x] = t[x];
            v.push_back(s);
            del.insert(x);
        }
    }
    for (auto x : del) {
        diff.erase(x);
    }
    for (auto it = diff.rbegin( );it != diff.rend( );it++) {
        s[*it] = t[*it];
        v.push_back(s);
    }
    for (auto x : v) {
        cout << x << endl;
    }
    return 0;
}

LICENSED UNDER CC BY-NC-SA 4.0
Comment