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


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

    Problem - A - Codeforces

    AC代码:

    1. #include
    2. using namespace std;
    3. using LL = long long;
    4. string a[] = {"Timur", "miurT", "Trumi", "mriTu"};
    5. void Solve() {
    6. int n;
    7. string s;
    8. cin >> n >> s;
    9. map<char, int> mp;
    10. mp['T'] = 1;
    11. mp['i'] = 1;
    12. mp['m'] = 1;
    13. mp['u'] = 1;
    14. mp['r'] = 1;
    15. if (n != 5) {
    16. cout << "NO\n";
    17. return;
    18. }
    19. for (int i = 0; i < n; i++) {
    20. if (mp[s[i]] == 0) {
    21. cout << "NO\n";
    22. return;
    23. } else if (mp[s[i]] == 2) {
    24. cout << "NO\n";
    25. return;
    26. } else {
    27. mp[s[i]] = 2;
    28. }
    29. }
    30. cout << "YES\n";
    31. }
    32. int main(){
    33. ios::sync_with_stdio(false);
    34. cin.tie(nullptr);
    35. int T;
    36. cin >> T;
    37. for (int i = 0; i < T; i++) {
    38. Solve();
    39. }
    40. return 0;
    41. }

    Problem - B - Codeforces

    AC代码:

    1. #include
    2. using namespace std;
    3. using LL = long long;
    4. void Solve() {
    5. int n;
    6. cin >> n;
    7. string s1, s2;
    8. cin >> s1 >> s2;
    9. for (int i = 0; i < n; i++) {
    10. if (s1[i] != s2[i] and (s1[i] == 'R' or s2[i] == 'R')) {
    11. cout << "NO\n";
    12. return;
    13. }
    14. }
    15. cout << "YES\n";
    16. }
    17. int main(){
    18. ios::sync_with_stdio(false);
    19. cin.tie(nullptr);
    20. int T;
    21. cin >> T;
    22. for (int i = 0; i < T; i++) {
    23. Solve();
    24. }
    25. return 0;
    26. }

    Problem - C - Codeforces

    AC代码:

    1. #include
    2. using namespace std;
    3. using LL = long long;
    4. struct node {
    5. int cnt;
    6. bool ok1, ok2, ok3;
    7. };
    8. void Solve() {
    9. int n;
    10. cin >> n;
    11. map mp;
    12. vector<int> a(3);
    13. for (int i = 0; i < 3; i++) {
    14. for (int j = 0; j < n; j++) {
    15. string s;
    16. cin >> s;
    17. mp[s].cnt++;
    18. if (i == 0) {
    19. mp[s].ok1 = true;
    20. } else if (i == 1) {
    21. mp[s].ok2 = true;
    22. } else {
    23. mp[s].ok3 = true;
    24. }
    25. }
    26. }
    27. for (auto it : mp) {
    28. if (it.second.cnt == 1) {
    29. if (it.second.ok1) {
    30. a[0] += 3;
    31. } else if (it.second.ok2) {
    32. a[1] += 3;
    33. } else {
    34. a[2] += 3;
    35. }
    36. } else if (it.second.cnt == 2) {
    37. if (it.second.ok1) {
    38. a[0]++;
    39. }
    40. if (it.second.ok2) {
    41. a[1]++;
    42. }
    43. if (it.second.ok3) {
    44. a[2]++;
    45. }
    46. }
    47. }
    48. for (int i = 0; i < 3; i++) {
    49. cout << a[i] << " \n"[i == 2];
    50. }
    51. }
    52. int main(){
    53. ios::sync_with_stdio(false);
    54. cin.tie(nullptr);
    55. int T;
    56. cin >> T;
    57. for (int i = 0; i < T; i++) {
    58. Solve();
    59. }
    60. return 0;
    61. }

    Problem - D - Codeforces

    AC代码:

    1. #include
    2. using namespace std;
    3. using LL = long long;
    4. void Solve() {
    5. int n;
    6. string s;
    7. cin >> n >> s;
    8. int mid = n / 2;
    9. int cnt = 0;
    10. LL ans = 0;
    11. vectorint, int>> a;
    12. if (n & 1) {
    13. for (int i = 0; i < mid; i++) {
    14. if (s[i] == 'L') {
    15. cnt++;
    16. ans += i;
    17. a.push_back(make_pair(n - i - 1, i));
    18. } else {
    19. ans += n - i - 1;
    20. }
    21. }
    22. for (int i = mid + 1; i < n; i++) {
    23. if (s[i] == 'R') {
    24. cnt++;
    25. ans += n - i - 1;
    26. a.push_back(make_pair(i, i));
    27. } else {
    28. ans += i;
    29. }
    30. }
    31. ans += mid;
    32. sort(a.begin(), a.end(), [&](pair<int, int> x, pair<int, int> y) {
    33. return x.first > y.first;
    34. });
    35. for (int i = 0; i < cnt; i++) {
    36. ans += a[i].first;
    37. if (a[i].second < mid) {
    38. ans -= a[i].second;
    39. } else {
    40. ans -= n - a[i].second - 1;
    41. }
    42. cout << ans << ' ';
    43. }
    44. for (int i = cnt; i < n; i++) {
    45. cout << ans << ' ';
    46. }
    47. cout << '\n';
    48. } else {
    49. for (int i = 0; i < mid; i++) {
    50. if (s[i] == 'L') {
    51. cnt++;
    52. ans += i;
    53. a.push_back(make_pair(n - i - 1, i));
    54. } else {
    55. ans += n - i - 1;
    56. }
    57. }
    58. for (int i = mid; i < n; i++) {
    59. if (s[i] == 'R') {
    60. cnt++;
    61. ans += n - i - 1;
    62. a.push_back(make_pair(i, i));
    63. } else {
    64. ans += i;
    65. }
    66. }
    67. sort(a.begin(), a.end(), [&](pair<int, int> x, pair<int, int> y) {
    68. return x.first > y.first;
    69. });
    70. for (int i = 0; i < cnt; i++) {
    71. ans += a[i].first;
    72. if (a[i].second < mid) {
    73. ans -= a[i].second;
    74. } else {
    75. ans -= n - a[i].second - 1;
    76. }
    77. cout << ans << ' ';
    78. }
    79. for (int i = cnt; i < n; i++) {
    80. cout << ans << ' ';
    81. }
    82. cout << '\n';
    83. }
    84. }
    85. int main(){
    86. ios::sync_with_stdio(false);
    87. cin.tie(nullptr);
    88. int T;
    89. cin >> T;
    90. for (int i = 0; i < T; i++) {
    91. Solve();
    92. }
    93. return 0;
    94. }

    Problem - E - Codeforces

    AC代码:

    1. #include
    2. using namespace std;
    3. using LL = long long;
    4. LL a[1010][1010];
    5. void Solve() {
    6. int n, q;
    7. cin >> n >> q;
    8. memset(a, 0, sizeof(a));
    9. for (int i = 0; i < n; i++) {
    10. LL x, y;
    11. cin >> x >> y;
    12. a[x][y] += x * y;
    13. }
    14. for (int i = 1; i <= 1000; i++) {
    15. for (int j = 1; j <= 1000; j++) {
    16. a[i][j] = a[i][j] + a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
    17. }
    18. }
    19. for (int o = 0; o < q; o++) {
    20. int hs, ws, hb, wb;
    21. cin >> hs >> ws >> hb >> wb;
    22. cout << a[hb - 1][wb - 1] - a[hb - 1][ws] - a[hs][wb - 1] + a[hs][ws] << '\n';
    23. }
    24. }
    25. int main() {
    26. ios::sync_with_stdio(false);
    27. cin.tie(nullptr);
    28. int T;
    29. cin >> T;
    30. for (int i = 0; i < T; i++) {
    31. Solve();
    32. }
    33. return 0;
    34. }

    Problem - F - Codeforces

    AC代码:

    1. #include
    2. using namespace std;
    3. using LL = long long;
    4. void Solve() {
    5. int n, m;
    6. cin >> n >> m;
    7. vector a(n);
    8. const vector<int> dirx = {1, -1, 0, 0, 1, -1, 1, -1};
    9. const vector<int> diry = {0, 0, 1, -1, 1, 1, -1, -1};
    10. for (int i = 0; i < n; i++) {
    11. cin >> a[i];
    12. }
    13. function<bool(int, int)> check = [&](int x, int y) {
    14. if (x < 0 or x >= n or y < 0 or y >= m) {
    15. return false;
    16. }
    17. return true;
    18. };
    19. for (int i = 0; i < n; i++) {
    20. for (int j = 0; j < m; j++) {
    21. if (a[i][j] == '*') {
    22. int cnt = 1;
    23. queueint, int>> qu;
    24. qu.push(make_pair(i, j));
    25. for (int k = 0; k < 8; k++) {
    26. int nx = i + dirx[k], ny = j + diry[k];
    27. if (check(nx, ny)) {
    28. if (a[nx][ny] == '*') {
    29. cnt++;
    30. qu.push(make_pair(nx, ny));
    31. }
    32. }
    33. }
    34. if (cnt != 3) {
    35. cout << "NO\n";
    36. return;
    37. } else {
    38. pair<int, int> x1, x2, x3;
    39. x1 = qu.front();
    40. qu.pop();
    41. x2 = qu.front();
    42. qu.pop();
    43. x3 = qu.front();
    44. qu.pop();
    45. if ((x1.first == x2.first and x1.first == x3.first) or (x1.second == x2.second and x1.second == x3.second)) {
    46. cout << "NO\n";
    47. return;
    48. } 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)) {
    49. int sum = 1;
    50. for (int k = 0; k < 8; k++) {
    51. int nx = x1.first + dirx[k], ny = x1.second + diry[k];
    52. if (check(nx, ny)) {
    53. if (a[nx][ny] == '*') {
    54. sum++;
    55. }
    56. }
    57. }
    58. if (sum != 3) {
    59. cout << "NO\n";
    60. return;
    61. }
    62. sum = 1;
    63. for (int k = 0; k < 8; k++) {
    64. int nx = x2.first + dirx[k], ny = x2.second + diry[k];
    65. if (check(nx, ny)) {
    66. if (a[nx][ny] == '*') {
    67. sum++;
    68. }
    69. }
    70. }
    71. if (sum != 3) {
    72. cout << "NO\n";
    73. return;
    74. }
    75. sum = 1;
    76. for (int k = 0; k < 8; k++) {
    77. int nx = x3.first + dirx[k], ny = x3.second + diry[k];
    78. if (check(nx, ny)) {
    79. if (a[nx][ny] == '*') {
    80. sum++;
    81. }
    82. }
    83. }
    84. if (sum != 3) {
    85. cout << "NO\n";
    86. return;
    87. }
    88. a[x1.first][x1.second] = '.';
    89. a[x2.first][x2.second] = '.';
    90. a[x3.first][x3.second] = '.';
    91. } else {
    92. cout << "NO\n";
    93. return;
    94. }
    95. }
    96. }
    97. }
    98. }
    99. cout << "YES\n";
    100. }
    101. int main() {
    102. ios::sync_with_stdio(false);
    103. cin.tie(nullptr);
    104. int T;
    105. cin >> T;
    106. for (int i = 0; i < T; i++) {
    107. Solve();
    108. }
    109. return 0;
    110. }

    Problem - G - Codeforces

    AC代码:

    1. #include
    2. using namespace std;
    3. using LL = long long;
    4. void Solve() {
    5. int n;
    6. cin >> n;
    7. LL c = (1ll << 31 - 1);
    8. int l = 0, r = 0;
    9. for (int i = 0; i < n - 2; i++) {
    10. if (i % 2 == 0) {
    11. l ^= i;
    12. } else {
    13. r ^= i;
    14. }
    15. }
    16. if ((l ^ c) == (r ^ c)) {
    17. l = 0, r = 0;
    18. for (int i = 0; i < n - 2; i++) {
    19. if (i % 2 == 0) {
    20. l ^= (i + 1);
    21. } else {
    22. r ^= (i + 1);
    23. }
    24. cout << i + 1 << " ";
    25. }
    26. if ((n - 2) % 2 == 0) {
    27. cout << (l ^ c) << " " << (r ^ c) << "\n";
    28. } else {
    29. cout << (r ^ c) << " " << (l ^ c) << "\n";
    30. }
    31. } else {
    32. for (int i = 0; i < n - 2; i++) {
    33. cout << i << " ";
    34. }
    35. if ((n - 2) % 2 == 0) {
    36. cout << (l ^ c) << " " << (r ^ c) << "\n";
    37. } else {
    38. cout << (r ^ c) << " " << (l ^ c) << "\n";
    39. }
    40. }
    41. }
    42. int main() {
    43. ios::sync_with_stdio(false);
    44. cin.tie(nullptr);
    45. int T;
    46. cin >> T;
    47. for (int i = 0; i < T; i++) {
    48. Solve();
    49. }
    50. return 0;
    51. }

  • 相关阅读:
    Python基础--PART1
    排序(二分法查找、冒泡排序、选择排序、插入排序以及快速排序)
    【数据结构基础_数组】Leetcode 48.旋转图像
    微光互联 TX800-U 扫码器无法输出中文到光标的问题
    .split(“,“, -1) 和 .split(“,“) 的区别
    面试求职者
    项目管理中的三大误区
    互联网Java工程师面试题·Spring篇·第二弹
    实验19:光敏传感器+继电器=光控智能灯实验
    postman登录鉴权之接口测试
  • 原文地址:https://blog.csdn.net/eyuhaobanga/article/details/126754401