传送门

A Compare T-Shirt Sizes

简单模拟,分情况讨论即可。

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 100010;

void solve() {
    string a, b;
    cin >> a >> b;
    if (a == b) {
        puts("=");
        return;
    }
    if (a.back() == 'S') {
        if (b.back() == 'M' || b.back() == 'L')puts("<");
        else if (b.back() == 'S') {
            if (b.size() < a.size())puts("<");
            else puts(">");
        }
    } else if (a.back() == 'L') {
        if (b.back() == 'M' || b.back() == 'S')puts(">");
        else if (b.back() == 'L') {
            if (b.size() < a.size())puts(">");
            else puts("<");
        }
    } else if (a.back() == 'M') {
        if (b.back() == 'S')puts(">");
        else if (b.back() == 'L')puts("<");
    }
}

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 Funny Permutation

构造题,我是直接达标找规律了,将排列1,2,3,4....n,将1,2移动到最后两位,其他往前移两位输出即可,其实也不用打表,推推就出来了,不难,1和3无论如何也不行,注意特判。

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 200010;

int a[N];

void solve() {
    int n;
    cin >> n;
    if (n == 1 || n == 3) {
        cout << -1 << endl;
        return;
    }
    if (n == 2) {
        cout << 2 << ' ' << 1 << endl;
        return;
    }
    for (int i = 3; i <= n; i++)cout << i << ' ';
    for (int i = 1; i <= 2; i++)cout << i << ' ';
    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 Minimize the Thickness

数据范围小,直接暴力的枚举即可,先把所有数的总和求出来,把能把这个数整除的数存到一个数组里,如何去遍历这个数组,求出每一种分割情况的最大长度,最后取个min,但要注意,最后输出的时候要判断一下,万一每个分割的长度不满足题目要求,那么就要输出n,否则就输出ans,vp时就因为这个点卡了好久,导致第四题都没做出来。

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 200010;

int n;

void solve() {
    cin >> n;
    vector<int> a(n + 10);
    vector<int> s(n + 10);
    vector<int> b;
    for (int i = 1; i <= n; i++)cin >> a[i], s[i] = s[i - 1] + a[i];
    int mx = *max_element(a.begin(), a.end());
    int mn = *min_element(a.begin(), a.end());
    //cout << s[n] << ' ' << mx << endl;
    for (int i = 2; i<=n; i++)if (s[n] % i == 0 && s[n] / i >= mx)b.push_back(i);
    if (!b.size()) {
        cout << n << endl;
        return;
    }
    //reverse(b.begin(), b.end());
    //for (auto i: b)cout << i << ' ';
//    cout << endl;
//    for(auto i:s)cout<<i<<' ';cout<<endl;
    bool ok = true;
    int aans = INT_MAX;
    for (auto i: b) {
        int res = s[n] / i;
        int pos = 0;
        int ans = 0;
        for (int j = 1; j <= n; j++) {
            if (s[j] - s[pos] == res) {
                ans = max(ans, j - pos);
                pos = j;
            }
        }
        if (pos == n) aans = min(aans, ans);
    }
    if(aans==INT_MAX)cout<<n<<endl;
    else cout << aans << 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 Masha and a Beautiful Tree

使用了分治的思想,根本不用建树,直接递归即可,先递归到最下面一层,如何判断两个数的相对大小,我们要找到一个规律,要变成题目要求的样子,那么左右哪一边的最小值一定要大于另一边的最大值,如果一边并不是全部严格大于另一边,则不行,标记一下即可,最后输出的时候判断一下。

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 262154;

int a[N];
int n;
int ans;
bool ok;

void dfs(int l,int r) {
    if (l >= r)return;
    int mid = l + r >> 1;
    dfs(l, mid);
    dfs(mid + 1, r);
//
    int mx1 = INT_MIN, mn1 = INT_MAX;
    for (int i = l; i <= mid; i++)mx1 = max(mx1, a[i]), mn1 = min(mn1, a[i]);
//    int mx2 = *max_element(a + mid + 1, a + r);
//    int mn2 = *min_element(a + mid + 1, a + r);
    int mx2 = INT_MIN, mn2 = INT_MAX;
    for (int i = mid + 1; i <= r; i++)mx2 = max(mx2, a[i]), mn2 = min(mn2, a[i]);
    if (mx1 > mn2 && mn1 < mx2)ok = false;
    else if (mn1 >= mx2)ans++;
}

void solve() {
    ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> a[i];
    ok = true;
    dfs(1, n);
    if (!ok)cout << -1 << endl;
    else cout << ans << 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;
}