---
# System prepended metadata

title: 'Codeforces Round #826 (Div. 3)解題心得'
tags: [CP]

---

###### tags: `CP`
# Codeforces Round #826 (Div. 3)解題心得
高中時就曾經聽說Codeforces這個網站，但這是我第一次正式參與線上競賽。雖然這次只解出兩題，但是競賽過程的成就感仍然讓我想繼續下去。

*A. Compare T-Shirt Sizes*
簡單的字串比對，考慮M，S，L並比較S，L前的X多寡決定大小
```
#include <iostream>

using namespace std;

int main()
{
    int T;
    int Size[100] = {0};
    Size['S'] = 1, Size['M'] = 2, Size['L'] = 3;
    string Size_1, Size_2;
    cin >> T;
    while(T--){
        int Size_1_Amount = 0, Size_2_Amount = 0;
        cin >> Size_1 >> Size_2;
        if(Size_1 == Size_2) cout << "=\n";
        else if(Size[Size_1[Size_1.size() - 1]] > Size[Size_2[Size_2.size() - 1]]) cout << ">\n";
        else if(Size[Size_1[Size_1.size() - 1]] < Size[Size_2[Size_2.size() - 1]]) cout << "<\n";
        else{
            for(auto it : Size_1){
                if(it == 'X') ++Size_1_Amount;
            }
            for(auto it : Size_2){
                if(it == 'X') ++Size_2_Amount;
            }

            if(Size_1[Size_1.size() - 1] == 'L' && Size_1_Amount > Size_2_Amount) cout << ">\n";
            else if(Size_1[Size_1.size() - 1] == 'L' && Size_1_Amount < Size_2_Amount) cout << "<\n";
            else if(Size_1[Size_1.size() - 1] == 'S' && Size_1_Amount > Size_2_Amount) cout << "<\n";
            else if(Size_1[Size_1.size() - 1] == 'S' && Size_1_Amount < Size_2_Amount) cout << ">\n";
        }
    }
}
```

*B. Funny Permutation*
觀察Permutation，可以發現當n = 3時，問題無解，否則將n分成奇偶數討論。n為奇數時，將數列1~n切成兩半輸出，因P<sub>i</sub> $\neq$ i，所以將後半部序列移至前半部輸出，之後輸出前半部。若n為偶數，直接倒序輸出，即為解。
```
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int T, N;
    cin >> T;
    while(T--){
        cin >> N;
        int Load = N, RLoad = 1;
        vector <int> Permutation;
        if(N == 1 || N == 3){
            cout << "-1\n";
            continue;
        }
        else if(N % 2){
            for(int i = 0; i < N; ++i){
                Permutation.push_back((i < N / 2)? Load : RLoad);
                if(i < N / 2) --Load;
                else ++RLoad;
            }
        }
        else{
            for(int i = 0; i < N; ++i){
                Permutation.push_back(Load--);
            }
        }
        for(auto it : Permutation){
            cout << it << " ";
        }
        cout << '\n';
    }
}
```