传送门

A Two Elevators

注意读题,读懂题目即可,比较两部电梯到达1楼所需要的时间。

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 200010;

int n;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans;
    a = a - 1;
    if (b > c)ans = b - 1;
    else ans = c - b + c - 1;
    if (a < ans)cout << 1 << endl;
    else if (a > ans)cout << 2 << endl;
    else cout << 3 << endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int h_h;
    cin >> h_h;
    //h_h = 1;
    while (h_h--)solve();
    return 0;
}

B Decode String

给一串数字过呢据题目要求的规则解密为字母,最后输出解密得到的字符串,这个题要么1位数字或3位数字为一个字母对应如果两位数字大于了26,则肯定是一位数字,否则是两位数字还要把后面跟着的0跳过,但还要特判一下特殊情况,就是以上两种情况都满足,要判断如果是三位数字后面的是不是0,如果是0,就只能是一位数字,否则是三位数字。

#include<bits/stdc++.h>

//#define int long long

using namespace std;

const int N = 200010;

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (i == s.size() - 1) {
            cout << (char) ('a' + s[i] - '0' - 1);
            continue;
        }
        int x = (s[i] - '0') * 10 + (s[i + 1] - '0');
        if (x <= 26 && s[i + 2] == '0' && s[i + 3] != '0')
            cout << (char) ('a' + x - 1), i += 2;
        else cout << (char) ('a' + s[i] - '0' - 1);
    }
    cout << endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int h_h;
    cin >> h_h;
    //h_h = 1;
    while (h_h--)solve();
    return 0;
}

C Jumping on Tiles

题意就是要求从起点到终点条约次数最多,先把起点和终点之间的差值算出来,再把每一个字母,在这个序列当中出现过的位置用两维的vector存起来,然后输出的时候要判断一下,起点更大就顺序输出,否则就倒序输出

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 200010;

void solve() {
    string s;
    cin >> s;
    vector<int> a[27];
    int sum = abs(s[0] - s[s.size() - 1]);
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        a[s[i] - 'a' + 1].push_back(i + 1);
    }
    int x = (s[0] - 'a' + 1);
    int y = (s[s.size() - 1] - 'a' + 1);
    for (int i = min(x, y); i <= max(x, y); i++) {
        ans += a[i].size();
    }
    cout << sum << ' ' << ans << endl;
    if (x <= y) {
        for (int i = min(x, y); i <= max(x, y); i++) {
            for (auto j: a[i])cout << j << ' ';
        }
    } else {
        for (int i = max(x, y); i >= min(x, y); i--) {
            for (auto j: a[i])cout << j << ' ';
        }
    }
    cout << endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int h_h;
    cin >> h_h;
    //h_h = 1;
    while (h_h--)solve();
    return 0;
}

D Friends and the Restaurant

赛时差一点点就出了,贪心的来做,将b[i]-a[i]的值存入数组升序排序,记录非负数的个数,每个负数只用一个正数来抵消,不断的往后找,如果满足条件非负数个数--,答案++,最后如果非负数的个数大于等二,再加上除以2的输出即可。

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 200010;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 10);
    vector<int> b(n + 10);
    vector<int> c;
    for (int i = 0; i < n; i++)cin >> a[i];
    for (int i = 0; i < n; i++)cin >> b[i];
    for (int i = 0; i < n; i++)c.push_back(b[i] - a[i]);
    sort(c.begin(), c.end());
    int pos = -2;
    int cntz = 0;
    for (int i = 0; i < n; i++) {
        if (c[i] >= 0)cntz++;
    }
    for (int i = 0; i < c.size(); i++) {
        if (c[i] >= 0 && pos == -2)pos = i - 1;
        //cout << c[i] << ' ';
    }
    //cout << endl << pos << ' ' << cntz << endl;
    int ans = 0;
    for (int i = pos, j = pos + 1; i >= 0 && j < n; i--, j++) {
        int res = c[i] + c[j];
        if (res >= 0)ans++, cntz--;
        else {
            res -= c[j];
            while (res < 0 && j < n) {
                if (res + c[j] >= 0) {
                    ans++;
                    cntz--;
                    break;
                }
                j++;
            }
        }
    }
    cout << ans + cntz / 2 << endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int h_h;
    cin >> h_h;
    //h_h = 1;
    while (h_h--)solve();
    return 0;
}