Codeforces Round #817 (Div. 4)(7/7)

不会有人div4的A还wa几发吧,那个人不会是我吧

Problem - A - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
string a[] = {"Timur", "miurT", "Trumi", "mriTu"};
void Solve() {
    int n;
    string s;
    cin >> n >> s;
    map<char, int> mp;
    mp['T'] = 1;
    mp['i'] = 1;
    mp['m'] = 1;
    mp['u'] = 1;
    mp['r'] = 1;
    if (n != 5) {
        cout << "NO\n";
        return;
    }
    for (int i = 0; i < n; i++) {
        if (mp[s[i]] == 0) {
            cout << "NO\n";
            return;
        } else if (mp[s[i]] == 2) {
            cout << "NO\n";
            return;
        } else {
            mp[s[i]] = 2;
        }
    }
    cout << "YES\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        Solve();
    }
    return 0;
}

Problem - B - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void Solve() {
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    for (int i = 0; i < n; i++) {
        if (s1[i] != s2[i] and (s1[i] == 'R' or s2[i] == 'R')) {
            cout << "NO\n";
            return;            
        }
    }
    cout << "YES\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        Solve();
    }
    return 0;
}

Problem - C - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
struct node {
    int cnt;
    bool ok1, ok2, ok3;
};
void Solve() {
    int n;
    cin >> n;
    map<string, node> mp;
    vector<int> a(3);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < n; j++) {
            string s;
            cin >> s;
            mp[s].cnt++;
            if (i == 0) {
                mp[s].ok1 = true;
            } else if (i == 1) {
                mp[s].ok2 = true;
            } else {
                mp[s].ok3 = true;
            }
        }
    }
    for (auto it : mp) {
        if (it.second.cnt == 1) {
            if (it.second.ok1) {
                a[0] += 3;
            } else if (it.second.ok2) {
                a[1] += 3;
            } else {
                a[2] += 3;
            }
        } else if (it.second.cnt == 2) {
            if (it.second.ok1) {
                a[0]++;
            }
            if (it.second.ok2) {
                a[1]++;
            }
            if (it.second.ok3) {
                a[2]++;
            }
        }
    }
    for (int i = 0; i < 3; i++) {
        cout << a[i] << " \n"[i == 2];
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        Solve();
    }
    return 0;
}

Problem - D - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void Solve() {
    int n;
    string s;
    cin >> n >> s;
    int mid = n / 2;
    int cnt = 0;
    LL ans = 0;
    vector<pair<int, int>> a;
    if (n & 1) {
        for (int i = 0; i < mid; i++) {
            if (s[i] == 'L') {
                cnt++;
                ans += i;
                a.push_back(make_pair(n - i - 1, i));
            } else {
                ans += n - i - 1;
            }
        }
        for (int i = mid + 1; i < n; i++) {
            if (s[i] == 'R') {
                cnt++;
                ans += n - i - 1;
                a.push_back(make_pair(i, i));
            } else {
                ans += i;
            }
        }
        ans += mid;
        sort(a.begin(), a.end(), [&](pair<int, int> x, pair<int, int> y) {
            return x.first > y.first;
        });
        for (int i = 0; i < cnt; i++) {
            ans += a[i].first;
            if (a[i].second < mid) {
                ans -= a[i].second;
            } else {
                ans -= n - a[i].second - 1;
            }
            cout << ans << ' ';
        }
        for (int i = cnt; i < n; i++) {
            cout << ans << ' ';
        }
        cout << '\n';
    } else {
        for (int i = 0; i < mid; i++) {
            if (s[i] == 'L') {
                cnt++;
                ans += i;
                a.push_back(make_pair(n - i - 1, i));
            } else {
                ans += n - i - 1;
            }
        }
        for (int i = mid; i < n; i++) {
            if (s[i] == 'R') {
                cnt++;
                ans += n - i - 1;
                a.push_back(make_pair(i, i));
            } else {
                ans += i;
            }
        }
        sort(a.begin(), a.end(), [&](pair<int, int> x, pair<int, int> y) {
            return x.first > y.first;
        });
        for (int i = 0; i < cnt; i++) {
            ans += a[i].first;
            if (a[i].second < mid) {
                ans -= a[i].second;
            } else {
                ans -= n - a[i].second - 1;
            }
            cout << ans << ' ';
        }
        for (int i = cnt; i < n; i++) {
            cout << ans << ' ';
        }
        cout << '\n';
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        Solve();
    }
    return 0;
}

Problem - E - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL a[1010][1010];
void Solve() {
    int n, q;
    cin >> n >> q;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) {
        LL x, y;
        cin >> x >> y;
        a[x][y] += x * y;
    }
    for (int i = 1; i <= 1000; i++) {
        for (int j = 1; j <= 1000; j++) {
            a[i][j] = a[i][j] + a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
        }
    }
    for (int o = 0; o < q; o++) {
        int hs, ws, hb, wb;
        cin >> hs >> ws >> hb >> wb;
        cout << a[hb - 1][wb - 1] - a[hb - 1][ws] - a[hs][wb - 1] + a[hs][ws] << '\n';
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        Solve();
    }
    return 0;
}

Problem - F - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void Solve() {
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    const vector<int> dirx = {1, -1, 0, 0, 1, -1, 1, -1};
    const vector<int> diry = {0, 0, 1, -1, 1, 1, -1, -1};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    function<bool(int, int)> check = [&](int x, int y) {
        if (x < 0 or x >= n or y < 0 or y >= m) {
            return false;
        }
        return true;
    };
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == '*') {
                int cnt = 1;
                queue<pair<int, int>> qu;
                qu.push(make_pair(i, j));
                for (int k = 0; k < 8; k++) {
                    int nx = i + dirx[k], ny = j + diry[k];
                    if (check(nx, ny)) {
                        if (a[nx][ny] == '*') {
                            cnt++;
                            qu.push(make_pair(nx, ny));
                        }
                    }
                }
                if (cnt != 3) {
                    cout << "NO\n";
                    return;
                } else {
                    pair<int, int> x1, x2, x3;
                    x1 = qu.front();
                    qu.pop();
                    x2 = qu.front();
                    qu.pop();
                    x3 = qu.front();
                    qu.pop();
                    if ((x1.first == x2.first and x1.first == x3.first) or (x1.second == x2.second and x1.second == x3.second)) {
                        cout << "NO\n";
                        return;
                    } else if ((abs(x1.first - x2.first + x1.second - x2.second) == 1 and abs(x1.first - x3.first + x1.second - x3.second) == 1) or (abs(x2.first - x1.first + x2.second - x1.second) == 1 and abs(x2.first - x3.first + x2.second - x3.second) == 1) or (abs(x3.first - x1.first + x3.second - x1.second) == 1 and abs(x3.first - x2.first + x3.second - x2.second) == 1)) {
                        int sum = 1;
                        for (int k = 0; k < 8; k++) {
                            int nx = x1.first + dirx[k], ny = x1.second + diry[k];
                            if (check(nx, ny)) {
                                if (a[nx][ny] == '*') {
                                    sum++;
                                }
                            }
                        }
                        if (sum != 3) {
                            cout << "NO\n";
                            return;
                        }
                        sum = 1;
                        for (int k = 0; k < 8; k++) {
                            int nx = x2.first + dirx[k], ny = x2.second + diry[k];
                            if (check(nx, ny)) {
                                if (a[nx][ny] == '*') {
                                    sum++;
                                }
                            }
                        }
                        if (sum != 3) {
                            cout << "NO\n";
                            return;
                        }
                        sum = 1;
                        for (int k = 0; k < 8; k++) {
                            int nx = x3.first + dirx[k], ny = x3.second + diry[k];
                            if (check(nx, ny)) {
                                if (a[nx][ny] == '*') {
                                    sum++;
                                }
                            }
                        }
                        if (sum != 3) {
                            cout << "NO\n";
                            return;
                        }
                        a[x1.first][x1.second] = '.';
                        a[x2.first][x2.second] = '.';
                        a[x3.first][x3.second] = '.';
                    } else {
                        cout << "NO\n";
                        return;
                    }
                }
            }
        }
    }
    cout << "YES\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        Solve();
    }
    return 0;
}

Problem - G - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void Solve() {
    int n;
    cin >> n;
    LL c = (1ll << 31 - 1);
    int l = 0, r = 0;
    for (int i = 0; i < n - 2; i++) {
        if (i % 2 == 0) {
            l ^= i;
        } else {
            r ^= i;
        }
    }
    if ((l ^ c) == (r ^ c)) {
        l = 0, r = 0;
        for (int i = 0; i < n - 2; i++) {
            if (i % 2 == 0) {
                l ^= (i + 1);
            } else {
                r ^= (i + 1);
            }
            cout << i + 1 << " ";
        }
        if ((n - 2) % 2 == 0) {
            cout << (l ^ c) << " " << (r ^ c) << "\n";
        } else {
            cout << (r ^ c) << " " << (l ^ c) << "\n";
        }
    } else {
        for (int i = 0; i < n - 2; i++) {
            cout << i << " ";
        }
        if ((n - 2) % 2 == 0) {
            cout << (l ^ c) << " " << (r ^ c) << "\n";
        } else {
            cout << (r ^ c) << " " << (l ^ c) << "\n";
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        Solve();
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值