Promote?

Solving

  1. A. Deletions of Two Adjacent Letters
    签到题
#include <bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin >> t;
    for(int i = 0; i < t; i++){
        string s;
        cin >> s;
        char c;
        cin >>c;
        int m = s.length();
        int flag = 0;
        for(int j = 0; j < m; j++){
            if(s[j] == c && j % 2 == 0){
                cout << "YES" << endl;
                flag = 1;
                break;
            }
        }
        if(flag == 0) cout << "NO" << endl;
    }
}
  1. B. DIV and MOD
    找规律
#include <bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin >> t;
    for(int i = 0; i < t; i++){
        long long l;
        long long r; 
        long long a;
        cin >> l >> r >> a;
        long long res1 = r / a + r % a;
        if (r%a >= r-l){
            cout << res1 << endl;
        }
        else{
            cout << max(r/a - 1+a-1, res1) << endl;
        }
    }
}
  1. C.Weight of the System of Nested Segments
    标准贪心
    两遍排序
    map
#include <bits/stdc++.h>
using namespace std;
bool cmp1(const vector<int>&a, const vector<int>&b){
    return a[1] < b[1];
}
bool cmp2(const vector<int>&a, const vector<int>&b){
    return a[0] < b[0];
}

int main(){
    map<int, int>mm;
    int t;
    cin >> t;
    for(int i = 0; i < t; i++){
        int n, m;
        cin >> n >> m;
        vector<vector<int>> x(m);
        for (int j = 0; j < m; j++){
            int tmp1, tmp2;
            cin >> tmp1 >> tmp2;
            x[j].push_back(tmp1);
            x[j].push_back(tmp2);
            mm[tmp1] = j;
        }
        sort(x.begin(), x.end(), cmp1);
        sort(x.begin(), x.begin()+n*2,cmp2);
        long long cnt = 0;
        for(int j = 0; j < n*2; j++){
            cnt += x[j][1];
        }
        cout << cnt << endl;
        for(int j = 0; j < n; j++){
            cout << mm[x[j][0]]+1 << " " << mm[x[2*n-1-j][0]]+1 << endl;
        }
        cout << endl;
    }
}
  1. D. Twist the Permutation
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    for(int i = 0; i < t; i++){
        int n;
        cin >> n;
        int a[n];
        int b[n+1];
        for(int j = 0; j < n; j++){
            cin >> a[j];
            b[a[j]] = j;
            cout << j << endl;
        }
        int res[n+1];
        for(int j = n; j >= 1; j--){
            if (b[j]+1 == j) {
                res[j] = 0;
                cout << "res: " << j << "," << res[j] << endl;
            }
            else{
                res[j] = b[j]+1;
                cout << "res: " << j << "," <<res[j] << endl;
                for(int k = 0; k < b[j]; k++){
                    b[a[k]] = n-(b[j]+1)+k;
                    cout << a[k] << "," << b[a[k]] << endl;
                }
                for(int k = b[j]+1; k < n; k++){
                    b[a[k]] = k-b[j]-1;
                    cout << a[k] << "," << b[a[k]] << endl;
                }
            }
        }
        for(int j = 1; j < n; j++){
            cout << res[j] << endl;
        }
    }
}

晚点写,先玩会P5 =。=