首页 > 其他分享 >Codeforces Round 855 (Div. 3)

Codeforces Round 855 (Div. 3)

时间:2023-12-17 16:45:54浏览次数:26  
标签:855 题意 cin int Codeforces st ++ solve Div

Codeforces Round 855 (Div. 3)

A. Is It a Cat?

题意:要求:

  • 字符串必须以只包含字母 "m "或 "M "的非空序列开始
  • 必须紧跟由'e'或'E'字符组成的非空序列
  • 必须紧接着仅由字符'o'或'O'组成的非空序列
  • 必须紧接着是仅由字符'w'或'W'组成的非空序列

思路:一个一个来(WA了三发注意这几个数都要有!!!!!!)

#include <bits/stdc++.h>

using namespace std;
char a[] = {'m', 'e', 'o', 'w'};
char b[] = {'M', 'E', 'O', 'W'};

void solve() {
    int n;
    cin >> n;
    string st;
    cin >> st;
    int num = 0;
    if (st[0] != a[0] && st[0] != b[0]) {
        cout << "NO\n";
        return;
    }
    int res = 1;
    for (int i = 0; i < n; i++) {
        if (st[i] == a[num] || st[i] == b[num]) {
            continue;
        } else if (num != 3 && (st[i] == a[num + 1] || st[i] == b[num + 1])) {
            num++;
            res++;
            continue;
        } else {
            cout << "NO\n";
            return;
        }
    }
    if (num == 3 && res == 4) cout << "YES\n";
    else cout << "NO\n";
}

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

B. Count the Number of Pairs

题意:a和A可以组成一对

操作:将小写字母转化成大写或者大写转化成小写

思路:分别看看aA有几个,然后看变化次数和对数

#include <bits/stdc++.h>

using namespace std;
int a[26], b[26];

void solve() {
    memset(a, 0, sizeof a);
    memset(b, 0, sizeof b);
    int n, k;
    cin >> n >> k;
    string st;
    cin >> st;
    for (int i = 0; i < n; i++) {
        if (st[i] >= 'a' && st[i] <= 'z') {
            a[st[i] - 'a']++;
        } else {
            b[st[i] - 'A']++;
        }
    }
    int ans = 0, res = 0;
    for (int i = 0; i < 26; i++) {
        ans += min(a[i], b[i]);
        res += abs(a[i] - b[i]) / 2;
    }
    cout << ans + min(res, k) << "\n";
}

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

C. Powering the Hero

ps:C1,C2就一起了,发现写的都能过

题意:当a[i]=0的时候就可以加前面的数,是的之前加的数最大

思路:很明显加的是之前的最大值(优先队列)(没开龙long longWA了三发)

#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve() {
    int n, res = 0;
    cin >> n;
    priority_queue<int> mp;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x > 0) {
            mp.push(x);
        } else if (!x && !mp.empty()) {
            res += mp.top();
            mp.pop();
        }
    }
    cout << res << endl;
}

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

D. Remove Two Letters

题意:删除两个连续的字符,问可以得到多少不同的字符串

思路:面对样例编程,假设是一样的会发现三个字符只有一个,假设两两相同会发现四个字母只有一个马,再看看发现只要a[i]==a[i+2]那么就会少一个

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n;
    cin >> n;
    string st;
    cin >> st;
    int ans = 0;
    for (int i = 0; i < n - 2; i++) {
        if (st[i] == st[i + 2]) ans++;
    }
    cout << n - ans - 1 << endl;
}

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

E1. Unforgivable Curse (easy version)

本来可以a的结果没考虑清楚零界点5

题意:操作:交换b串中i-j3||i-j4的;目的:b串=a串

思路:可以交换三和四就等于相邻的数可以交换,那么只需要统计数是否相等即可(特判n<=5的时候)

1.n<=3发现没法交换,直接比

2.n==4只能1和4交换23必须相等

3.n==5中间的数是不能交换的所以必须相等

#include <bits/stdc++.h>

using namespace std;
#define int long long
int a[26], b[26];

void solve() {
    int n, k;
    cin >> n >> k;
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; i++) {
        a[s[i] - 'a']++;
    }
    for (int i = 0; i < n; i++) {
        b[t[i] - 'a']++;
    }
    if (n <= 3) {
        if (s != t) {
            cout << "NO\n";
            return;
        }
    }
    if (n == 4) {
        if (s[1] != t[1] || s[2] != t[2]) {
            cout << "NO\n";
            return;
        }
    }
    if (n == 5) {
        if (s[2] != t[2]) {
            cout << "NO\n";
            return;
        }
    }
    for (int i = 0; i < 26; i++) {
        if (a[i] != b[i]) {
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}

signed main() {

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

E2. Unforgivable Curse (hard version)

题意:与简单版相比就是k不一样

思路:不能变换的情况1.i+k>n 2.i-k<0

#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve() {
    int n, k;
    cin >> n >> k;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i <= n; i++) {
        if (s[i] != t[i] && i - k < 0 && i + k >= n) {
            cout << "NO" << "\n";
            return;
        }
    }
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    if (s == t) {
        cout << "YES" << "\n";
        return;
    }
    cout << "NO" << "\n";
}

signed main() {

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

F. Dasha and Nightmares

题意:给定n个字符串要让他们满足一下要求,请问有几种方法
$$

  1. (l_x+l_y)为奇数
    $$

$$
2.相加之后所含字母总数为25
$$

$$
3.每个种类的数量为奇数
$$

思路:只需奇偶性,干脆直接化成0,1来表示奇偶性,然后再枚举每个字母即可

ps:代码还在debug中,感觉思路是这样

标签:855,题意,cin,int,Codeforces,st,++,solve,Div
From: https://www.cnblogs.com/bbbbear/p/17909282.html

相关文章

  • Codeforces Round 913 (Div. 3)
    CodeforcesRound913(Div.3)A:ABCA.Rook简单题,就两个循环搞定(直接上码)#include<bits/stdc++.h>usingnamespacestd;voidsolve(){chara;intb;cin>>a>>b;for(inti=1;i<=8;i++){if(i!=b){......
  • Codeforces Round 863 (Div. 3)
    CodeforcesRound863(Div.3)A.InsertDigit题意:插入一个字母使得这个数字最大化思路:只要从前往后便利就行#include<iostream>usingnamespacestd;voidsolve(){intn,k;cin>>n>>k;boolx=true,y=false;for(inti=0;i<n;i++){......
  • Codeforces Round 913 (Div. 3)
    CF1907总结A.Rook题面翻译给出车在国际象棋棋盘中的位置,输出其可到达的坐标(不必在意顺序)。车可以横着或竖着走任意格数。分析题意明了,输出车所在行和列所有格子的序号(除车所在位置外)。code#include<bits/stdc++.h>usingnamespacestd;intt;voidsolve(){ string......
  • Codeforces Round 891 (Div3)
    CodeforcesRound891(Div.3)A.ArrayColoring这个我vp的时候写复杂了,想不到答案的思路这么清晰,将两部分分别看,将偶数加进去其奇偶性不变,只有奇数加进去才会改变奇偶性,so只有改变偶数次奇偶性才能使其奇偶性相同,所以cnt%2==0.#include<bits/stdc++.h>usingnamespacestd;......
  • Codeforces Round 816 (Div. 2) VP
    基本情況A秒了,B错一次之后也过了,C没思路。B.BeautifulArrayProblem-B-Codeforcesvoidsolve(){ longlongn,k,b,s; memset(ans,0,sizeof(ans)); std::cin>>n>>k>>b>>s; if(s<b*k){std::cout<<"-1\n";ret......
  • Codeforces Round 815 (Div. 2)
    基本情况脑子太不清楚了。A题有思路,但是各种细节问题(数论题太不熟练了),错了好几次才过。B题直接分析数据愣猜一个解,猜对了。A.BurenkaPlayswithFractionsProblem-A-Codeforces难点在分析输出\(1\)的情况。我的想法是通分,然后直接比分子是否互相整除,想法很对,但是......
  • Codeforces Round 915 (Div. 2)
    A.ConstructiveProblems看了一眼数据,猜测可能是n,m里的最大#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ inta,b; cin>>a>>b; intans=max(a,b); cout<<ans<<"\n";}intmain(){ ios::sync_with_stdio(false);cin.tie......
  • Codeforces Round 915 (Div. 2)
    CodeforcesRound915(Div.2)唉,菜狗。A-CoverinWaterintmain(){IOS;for(cin>>_;_;--_){cin>>n>>m;cout<<max(n,m)<<'\n';}return0;}B-Begginer'sZelda除......
  • Educational Codeforces Round 159 (Rated for Div. 2) C. Insert and Equalize (贪心+
    EducationalCodeforcesRound159(RatedforDiv.2)C.InsertandEqualize思路:首先对\(a\)进行排序,然后对所有差值取gcd,获得可用的最大因子\(gc\),答案有两种情况:一种是\(a_{n+1}\)在$a_1\(~\)a_n$范围内,这时要获得最大的位置一种情况是$a_1\(~\)a_n$......
  • [Codeforces] CF1774B Coloring
    CF1774BColoring题意Cirno_9baka的纸条上有\(n\)个格子,他觉得空白的纸条看着有点无趣,于是想在纸条的格子上涂上\(m\)种颜色。同时,他认为第\(i\)种颜色必须要用\(a_i\)次,且每连续\(k\)个格子里涂的颜色必须互不相同。Cirno_9baka想知道有没有这样的一种涂色方案能......