• Educational Codeforces Round 134 (Rated for Div. 2) A~D


    Educational Codeforces Round 134 (Rated for Div. 2) A~D

    A - Image

    #include
    
    void solve()
    {
        char a[4];
        std::map<char, int> mp;
        int cnt = 0;
        for (int i = 0; i < 4; i++) {
            std::cin >> a[i];
            if (!mp[a[i]]) {cnt++; mp[a[i]] = 1;}
        }
        std::cout << cnt - 1 << "\n";
    }
    
    int main()
    {
        int T;
        std::cin >> T;
        while (T--) solve();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    B - Deadly Laser

    #include
    
    void solve()
    {
        int n, m, sx, sy, d;
        std::cin >> n >> m >> sx >> sy >> d;
        if ((sx + d >= n && sy + d >= m)) {std::cout << "-1\n"; return;}
        if ((sx - d <= 1 && sx + d >= n)) {std::cout << "-1\n"; return;}
        if ((sx - d <= 1 && sy - d <= 1)) {std::cout << "-1\n"; return;}
        if ((sy - d <= 1 && sy + d >= m)) {std::cout << "-1\n"; return;}
        std::cout << n + m - 2 << "\n";
    }
    
    int main()
    {
        int T;
        std::cin >> T;
        while (T--) solve();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    C - Min-Max Array Transformation

    题意:给出数组a和b,满足条件 b i = a i + d i b_i = a_i + d_i bi=ai+di要求构造数组dmin和dmax,代表d数组每个元素的上下界,要求求出来b排序之后是给定的数组,a和b都是不递减的非负数组
    思路:对于最小值直接找到比 a i a_i ai大的 b j b_j bj满足 d i = b j − a i d_i=b_j-a_i di=bjai。对于最大值,首先可以发现,一个数字不能构造比自己小的数组,所以我们对于一段区间要找到它能容纳的最大 b l b_l bl就行了

    #include
    
    void solve()
    {
        int n;
        std::cin >> n;
        std::vector<int> a(n), b(n), dmin(n), dmax(n);
        for (int i = 0; i < n; i++) std::cin >> a[i];
        for (int i = 0; i < n; i++) std::cin >> b[i];
        for (int i = 0; i < n; i++) {
            dmin[i] = std::lower_bound(b.begin(), b.end(), a[i]) - b.begin();
            dmin[i] = b[dmin[i]] - a[i];
        }
        int l = n - 1;
        for (int i = n - 1; i >= 0; i--) {
            dmax[i] = b[l] - a[i];
            if (lower_bound(b.begin(), b.end(), a[i]) - b.begin() == i) l = i - 1;
        }
        for (int i = 0; i < n; i++) std::cout << dmin[i] << " \n"[i == n - 1] ;
        for (int i = 0; i < n; i++) std::cout << dmax[i] << " \n"[i == n - 1] ;
        std::cout << "\n";
    }
    
    int main()
    {
        int T;
        std::cin >> T;
        while (T--) solve();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    D - Maximum AND

    题意:给出数组a和b, c i = a x ⊕ b y c_i = a_x \oplus b_y ci=axby,现在要求 m a x { c 1 & c 2 & c 3 . . . & c n } max\{c_1\&c_2\&c_3...\&c_n\} max{c1&c2&c3...&cn}
    思路:我们对于二进制位拆位,因为 c i = a x ⊕ b y c_i=a_x \oplus b_y ci=axby,所以假如答案是 1001010 1001010 1001010,也就代表a和b的01状态要相反,所以把b取反从高位枚举ans这一位置的情况,看a和b&上ans的情况是不是一样,一样说明这一位可以置1

    #include
    
    void solve()
    {
        int n;
        std::cin >> n;
        std::vector<int> a(n), b(n);
        for (int i = 0; i < n; i++) std::cin >> a[i];
        for (int i = 0; i < n; i++) {std::cin >> b[i]; b[i] = ~b[i];}
        int ans = 0;
        for (int t = 29; t >= 0; t--) {
            ans |= (1 << t);
            std::map<int, int> mpa, mpb;
            for (int i = 0; i < n; i++) {
                mpa[a[i] & ans]++;
                mpb[b[i] & ans]++;
            }
            int f = 1;
            for (auto m : mpa) {
                if (m.second != mpb[m.first]) {f = 0; break;}
            }
            if (f) continue;
            ans ^= (1 << t);
        }
        std::cout << ans << "\n";
    }
    
    int main()
    {
        int T;
        std::cin >> T;
        while (T--) solve();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
  • 相关阅读:
    【设计模式】四、工厂模式
    一文了解io.ReadAtLeast函数
    数据库系统原理与应用教程(063)—— MySQL 练习题:操作题 39-50(七)
    AE& VAE 代码和结果记录
    【python】无限量PPT免费下载?找模板在不怕心仪得不能用啦
    【23真题】碰瓷重邮成电,题目Mini版本!
    Best Websites to Download Cracked Software for Free
    MySQL数据库 #3
    利用Redis实现向量相似度搜索:解决文本、图像和音频之间的相似度匹配问题
    [附源码]JAVA毕业设计口腔医院网站(系统+LW)
  • 原文地址:https://blog.csdn.net/qq_51672768/article/details/126569510