ZZJC新生训练赛第十二场题解

链接:https://www.nowcoder.com/acm/contest/94763
密码:ddgfhn615

难度分类(同一难度下按字典序上升)

  • 入门: G
  • 简单: C, E, A
  • 中等: F, D
  • 困难: B, H

G-解题思路

按照题意模拟即可

G-代码实现

#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    std::string s;
    std::cin >> s;

    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
    
    if (s == "yes") {
        std::cout << "accept";
    } else {
        std::cout << "wrong answer";
    }
}
print('accept' if input().lower() == 'yes' else 'wrong answer')

C-解题思路

对数字降序看看有没有变化就能得出答案

C-代码实现

#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    int t;
    std::cin >> t;

    while (t--) {
        std::string s1, s2;
        std::cin >> s1;
        s2 = s1;

        std::sort(s1.begin(), s1.end(), std::greater<>());

        if (s1 == s2) {
            std::cout << "NO\n";
        } else {
            std::cout << "YES\n";
        }
    }
}

E-解题思路

按照题意纯模拟即可,注意数据范围,本题需要开long long

E-代码实现

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    i64 n, x, ans = 0;
    std::cin >> n >> x;

    for (int i = 0; i < n; i++) {
        int t;
        std::cin >> t;

        if (x) {
           if (x > 0) {
               x -= t;
           } else {
               x += t;
           }
           ans += t;
        } else {
            break;
        }
    }

    std::cout << ans;
}

A-解题思路

显然至少要三条边才能组成一个封闭图形,所以先统计长度相等的边数,然后在满足数量的长度里选最小的边数*3即可。(注意任意大于3的边数取3才是最小的)

A-代码实现

#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie();
    std::cout.tie();

    int t;
    std::cin >> t;

    while (t--) {
        int n;
        std::cin >> n;

        std::map<int, int> mp;
        for (int i = 0; i < n; i++) {
            int x;
            std::cin >> x;

            mp[x]++;
        }
        
        int f = 1;
        for (auto [x, y]: mp) {
            if (y >= 3) {
                std::cout << "yes\n";
                std::cout << x * 3 << "\n";
                f = 0;
                break;
            }
        }
        
        if (f) {
            std::cout << "no\n";
        }
    }
}

F-解题思路

先成对的1*3能填就填,记得要先%3排除1*2的影响,这样就可以消除后续1*3砖块的影响,然后再看在这个条件下用1*2能否填充即可

F-代码实现

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    int t;
    std::cin >> t;
    
    while (t--) {
        int a, b, n;
        std::cin >> a >> b >> n;
        
        c = n % 3;
        n -= c;
        n -= std::min(3 * (b / 2), n);
        
        if (n + c <= a) {
            std::cout << "YES\n";
        } else {
            std::cout << "NO\n";
        }
    }
}

D-解题思路

通常会考虑答案是能表示第一个大于等于n的二的幂,但是不正确,打表可以发现还需要对n==2进行特判

D-代码实现

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    int t;
    std::cin >> t;

    while (t--) {
        i64 n;
        std::cin >> n;

        if (n == 2) {
            std::cout << 1 << "\n";
            continue;
        }

        i64 x = 1;
        while (x < n) {
            x *= 2;
        }

        std::cout << x << "\n";
    }
}

B-解题思路

一道赤石题,按照题目进行格式筛选即可(py高光时刻,正则一行秒了)

B-代码实现

import re; [print("Yes" if re.compile(r'^[a-z0-9](?:[a-z0-9.]{0,62}[a-z0-9])?@[a-z0-9](?:[a-z0-9.-]{0,253}[a-z0-9])?$', re.I).fullmatch(input()) else "No") for _ in range(int(input()))]

H-解题思路

题目的意思是在不打乱每个ai中数字相对顺序的情况下,找到将所有ai拼接起来的最大字典序,可以优先队列维护每次要挑选的数字,取出它的第一个数字(也就是当前能选的最大的数字),然后剔除并塞回队列,这样就可以保证没有打乱相对顺序,重复操作直到所有待选择的数字为空就能获得答案

H-代码实现

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    int n;
    std::cin >> n;

    std::priority_queue<std::string> pq;
    for (int i = 0; i < n; i++) {
        std::string x;
        std::cin >> x;
        pq.push(x);
    }

    std::string ans = "";
    while (!pq.empty()) {
        std::string s = pq.top();
        pq.pop();
        ans += s[0];
        s = s.substr(1);
        if (!s.empty()){
           pq.push(s);
        }
    }
    
    std::cout << ans;
}
posted @   udiandianis  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
  1. 1 山海不可平 CMJ
山海不可平 - CMJ
00:00 / 00:00
An audio error has occurred.

纯音乐,请欣赏

点击右上角即可分享
微信分享提示