首页 > 其他分享 >Codeforces Round #843 (Div. 2)

Codeforces Round #843 (Div. 2)

时间:2023-01-10 23:12:57浏览次数:56  
标签:843 int ++ Codeforces substr solve Div find size

Codeforces Round #843 (Div. 2)

https://codeforces.com/contest/1775
CD都不会写的垃圾罢了

A1. Gardener and the Capybaras (easy version)

#include <bits/stdc++.h>

using namespace std;

void solve () {
    string s;
    cin >> s;
    for (int i = 0; i < s.size (); i++) {
        for (int j = i + 1; j < s.size (); j++) {
            //0,i  i+1,j   j+1,n
            string a = s.substr (0, i + 1), b = s.substr (i + 1, j - i), c = s.substr (j + 1, s.size () - j);
            if (max({a, b, c}) == b || min ({a, b, c}) == b) {
                cout << a << ' ' << b << ' ' << c << endl;
                return ;
            }
        }
    }

    cout << ":(" << endl;
}

int main () {
    int t;
    cin >> t;
    while (t --)    solve ();
}

//aab
//baa
//baaaa

A2. Gardener and the Capybaras (hard version)

#include <bits/stdc++.h>

using namespace std;

void solve () {
    string s, a, b, c;
    cin >> s;
    int n = s.size ();
    //max
    a = s[0];
    int find = -1, cntb = 0;
    for (int i = 2; i < n; i++) {
        if (s[i] == 'b')    cntb ++;
    }
    for (int i = n - 1; i > 1; i--) {
        if (s[i] == 'a') {
            find = i;
            break;
        }
    }
    if (find == -1 || !cntb) {
        b = s.substr (1, n - 2);
        c = s[n - 1];
    }
    else {
        int len1 = find - 1, len2 = n - find;
        b = s.substr (1, len1), c = s.substr (find, len2);
    }
    if (b == max ({a, b, c})) {
        cout << a << ' ' << b << ' ' << c << endl;
        return ;
    }

    //min
    int posa = -1;
    for (int i = 1; i < n - 1; i++) {
        if (s[i] == 'a') {
            posa = i;
            break;
        }
    }
    if (posa != -1) {
        for (int i = 0; i < posa; i++)  cout << s[i];
        cout << ' ' << s[posa] << ' ';
        for (int i = posa + 1; i < n; i++)  cout << s[i];
        cout << endl;
        return ;
    }

    cout << ":(" << endl;
}

int main () {
    int t;
    cin >> t;
    while (t --)    solve ();
}

//aab
//baa
//baaaa

B. Gardener and the Array

#include <bits/stdc++.h>

using namespace std;

void solve () {
    int n, m, x;
    cin >> n;
    map<int, int> mp;
    vector <int> v[n+1];
    for (int i = 1; i <= n; i++) {
        cin >> m;
        for (int j = 1; j <= m; j++) {
            cin >> x;
            mp[x] ++;
            v[i].push_back (x);
        }
    }
    for (int i = 1; i <= n; i++) {
        bool suc = true;
        for (auto j : v[i]) {
            mp[j] --;
            if (mp[j] == 0) {
                suc = false;
                break;
            }
            mp[j] ++;
        }
        if (suc) {
            cout << "Yes\n";
            return ;
        }
    }  
    cout << "No\n";
}

int main () {
    int t;
    cin >> t;
    while (t --)    solve ();
}


//check相邻的两个数是否有包含关系

C. Interesting Sequence

D. Friendly Spiders

E. The Human Equation

F. Laboratory on Pluto

标签:843,int,++,Codeforces,substr,solve,Div,find,size
From: https://www.cnblogs.com/CTing/p/17041645.html

相关文章

  • Codeforces Round #843 (Div. 2) 题解
    A题目大意给你一个只含字母a,b字符串,要把它拆分成三段,使得其中间那段要么同时小于等于两边要么同时大于等于两边。题解由于只有a,b我们可以分讨解决如果\([2,......
  • Educational Codeforces Round 141 (Rated for Div. 2)(B,C,D)
    EducationalCodeforcesRound141(RatedforDiv.2)(B,C,D)BB这个题的大意是我们需要构造一个矩阵,我们需要这个矩阵的一个位置和它相邻位置的绝对值的不同数量最多我猜......
  • Educational Codeforces Round 141 (Rated for Div. 2)
    A-MakeitBeautiful题意:给出一个序列a,要求重新排列它,使前\(i-1\)个数之和不等于\(a_i\)思路:数据范围很小。用桶存数字,然后由大到小每种数字为一组循环输出即可赛时......
  • 2023.1.9(Educational Codeforces Round 141 & NEERC2017)
    A.YetAnotherTournamentLinkhttps://codeforces.com/contest/1783/problem/CStatement除了你以外有\(n\)个人,编号为\(0\ton-1\),每个人有两个权值\(a_i\)和......
  • Codeforces Round #645 (Div. 2) A-D
    A.ParkLighting题意:用1*2的方格去填充n*m的格子,可以重叠摆放,至少需要多少个分析:不重叠的情况下,横着摆与竖着摆的最少数量是一样的,贡献为\(\lfloor\frac{n......
  • div背面隐藏属性
    我们知道div这个dom元素视图是可分为:正面与背面——两个视觉面的。一般我们只关注正面视觉展示,但如果加上一些翻转效果时,背面展示可能会影响整体视觉效果。这个时候我......
  • Codeforces 1704 F Colouring Game 题解 (结论,SG函数)
    题目链接首先看R和B的数量不等的情况(很多博弈题都是先比较两种物品的数量,相等的情况再用SG函数之类的技巧),结论是R多Alice必赢,B多Bob必赢。证明:来看R比B多的情况,定义两人......
  • Educational Codeforces Round 114 D(搜索剪枝)
    D.TheStrongestBuild题目大意:给定n个位置,每个位置有c\({_i}\)个可选能力值(能力值升序给出即a\({_1}\)<a\({_2}\)<a\({_3}\)<...<a\({_{ci}}\)),你可以在每个......
  • CodeForces - 510C Fox And Names
    CodeForces-510CFoxAndNames题解:建图+拓扑排序首先题目想让你按照给定的字符串修改字母表的字母序,我们很容易想到拓扑排序,但是这怎么建图?实际上对于两个输入的字......
  • Namomo Winter Camp D3 Div2 简易题解
    题目提交链接ProblemK.KotlinIsland首先不用考虑描边(那样和不画这条边是一样的)。那么剩下的就是在长度和宽度内枚举了。显然可以知道长宽最多画\((n-1)/2\)和......