首页 > 其他分享 >[Codeforces Round 855 (Div. 3)](https://codeforces.com/contest/1800)

[Codeforces Round 855 (Div. 3)](https://codeforces.com/contest/1800)

时间:2023-12-05 20:01:51浏览次数:42  
标签:855 cout 1800 int contest long -- solve define

Codeforces Round 855 (Div. 3)

A. Is It a Cat?

为什么这个A这么麻烦

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
    int n;
    string s;
    cin>>n>>s;
    s = " " + s;
    int cnt1=0,cnt2=0,cnt3=0,cnt4=0;
    for(int i=1;i<=n;i++){
        if(s[i]=='m'||s[i]=='M'){
            cnt1++;
            if(cnt2+cnt3+cnt4>0){
                cout<<"NO"<<endl;
                return;
            }
        }else if(s[i]=='e'||s[i]=='E'){
            cnt2++;
            if(cnt3+cnt4>0){
                cout<<"NO"<<endl;
                return;
            }
        }else if(s[i]=='o'||s[i]=='O'){
            cnt3++;
            if(cnt4){
                cout<<"NO"<<endl;
                return;
            }
        }else if(s[i]=='w'||s[i]=='W'){
            cnt4++;
        }else{
            cout<<"NO"<<endl;
            return;
        }
    }
    if(!cnt1||!cnt2||!cnt3||!cnt4){
        cout<<"NO"<<endl;
        return;
    }
    cout<<"YES"<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--) solve();
    return 0;
}

B. Count the Number of Pairs

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    map<int,int> cnt;
    for(int i=0;i<n;i++)
        cnt[s[i]]++;
    int ans=0;
    int x=0;
    for(int i='A';i<='Z';i++){
        int y=min(cnt[i],cnt[i+'a'-'A']);
        ans += y;
        x = max(cnt[i],cnt[i+'a'-'A'])-y;
        if(k >= x/2){
            ans+=x/2;
            k  -=x/2;
        }else{
            ans+=k;
            k=0;
        }
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--) solve();
    return 0;
}

C1\2. Powering the Hero

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
    priority_queue<int,vector<int>,less<int>> path;
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x==0){
            if(path.size()){
                ans+=path.top();
                path.pop();
            }
        }else path.push(x);
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--) solve();
    return 0;
}

D. Remove Two Letters

刚开始开map写了个暴力,结果mle了。

要注意一下,如果s[i-1]==s[i+1]那么就一定会有一次重复。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 2e5 + 10;

void solve(){
    int n;
    string s;
    cin>>n>>s;
    int cnt=0;
    for(int i=1;i<s.size()-1;i++)
        if(s[i-1]==s[i+1]) cnt++;
    cout<<n-1-cnt<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--) solve();
    return 0;
}

E1\2. Unforgivable Curse

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
    int n,k;
    string s,t;
    cin>>n>>k;
    cin>>s>>t;
    s = " " + s;
    t = " " + t;
    vector<int> cnt1(26,0),cnt2(26,0);
    for(int i=1;i<=n;i++){
        if(i-k<1&&i+k>n)
        {
            if(s[i]!=t[i])
            {
                cout<<"NO"<<endl;
                return;
            }
        }
        else
        {
            cnt1[s[i]-'a']++;
            cnt2[t[i]-'a']++;
        }
    }
    for(int i=0;i<26;i++)
    {
        if(cnt1[i]!=cnt2[i])
        {
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--) solve();
    return 0;
}

F. Dasha and Nightmares

#include <bits/stdc++.h>
//#define int long long
#define endl '\n'
using namespace std;

const int N = 2e5 + 10;
string s;
int a[N] , b[N] ,cnt[1<<26];
int x[26];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        for(int j=0;j<s.size();j++)
        {
            a[i] |= (1<<(s[j]-'a'));
            b[i] ^= (1<<(s[j]-'a'));
        }
    }
    long long ans=0;
    for(int j=0;j<26;j++)
    {
        int target = (1<<26) - 1 - (1<<j);
        for(int i=1;i<=n;i++)
        {
            if(a[i]>>j & 1) continue;
            cnt[b[i]]++;
            ans += cnt[b[i]^target];
            //cout<<ans<<endl;
        }
        for(int i=1;i<=n;i++){
            if(a[i]>>j & 1) continue;
            cnt[b[i]]--;
        }
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--) solve();
    return 0;
}

标签:855,cout,1800,int,contest,long,--,solve,define
From: https://www.cnblogs.com/zfxyyy/p/17878043.html

相关文章

  • AtCoder Beginner Contest 331
    A-Tomorrow(abc331A)题目大意给定一年的月数和一月的天数,以及当天日期,问次日的日期。解题思路一个简单的进制加法运算,超出进制数则向前加一。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=longlong;intmain(void){ios::sync_with_st......
  • The 13th Shandong ICPC Provincial Collegiate Programming Contest
    A.Orders按照订单的结束时间排序,然后遍历一遍即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongusingpii=pair<int,int>;usingi32=int32_t;voidsolve(){intn,k;cin>>n>>k;vector<pii>p(n);f......
  • [Educational Codeforces Round 159 (Rated for Div. 2)](https://codeforces.com/con
    EducationalCodeforcesRound159(RatedforDiv.2)好困,差点没打A-BinaryImbalance#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;voidsolve(){ strings; intn; cin>>n; cin>>s; if(n==......
  • AtCoder Beginner Contest 328
    AtCoderBeginnerContest328链接:ToyotaProgrammingContest2023#7(AtCoderBeginnerContest328)-AtCoderA题意:给定n个数,将小于等于x的数加起来输出。#include<bits/stdc++.h>#defineintlonglong#defineendl'\n';usingnamespacestd;voidsolve(){......
  • AtCoder Beginner Contest 331
    AtCoderBeginnerContest331这场状态好差,下午的校赛也打的好差。A-Tomorrow#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;voidsolve(){intM,D;inty,m,d;cin>>M>>D>>y>>m>&......
  • AtCoder Beginner Contest 331 G Collect Them All
    洛谷传送门AtCoder传送门设数字\(i\)第一次拿到的时间为\(t_i\),所求即为\(E(\max\limits_{i=1}^mt_i)\)。施min-max容斥,有:\[\begin{aligned}E(\max\limits_{i=1}^mt_i)&=\sum\limits_{T\subseteq[1,m]\landT\ne\varnothing}(-1)^{|T|-1}E(\min\l......
  • 2023-2024 CTU Open Contest
    A.Beth'sCookiesn=int(input())s=input()res=[]foriins:ifres==[]:res.append(i)elifi=='(':ifres[-1]==')':res.append("*")res.append(i)else:......
  • AtCoder Beginner Contest 331
    B-BuyOneCartonofMilk难度:⭐题目大意选择有三种套餐,6个鸡蛋S元,8个鸡蛋M元,12个鸡蛋L元;问如果要买至少N个鸡蛋,最少花费多少钱;解题思路一道入门级dp;神秘代码#include<bits/stdc++.h>#defineintlonglong#defineIOSios::sync_with_stdio(false......
  • The 13th Shandong ICPC Provincial Collegiate Programming Contest
    Preface昨天VP的那场没有字符串还没有原形毕露,今天遇到一个后期字符串直接和祁神大眼瞪小眼了最后一个半小时祁神狂冲F成功写出两个version的假算法,而我已经滚去补之前欠下的题目了赛后被徐神狠狠拷打了,评价为徐神是我们的红太阳,没有他我们都不能活A.Orders签到,按截止时间......
  • AtCoder Beginner Contest 295
    B-Bombs题意:就是说有一种炸弹,能炸曼哈顿距离的障碍物,要你打印出炸完后的图模拟#include<bits/stdc++.h>usingnamespacestd;charmp[50][50];voidsolve(){ intn,m; cin>>n>>m; for(inti=1;i<=n;i++){ for(intj=1;j<=m;j++){ cin>>mp[i][j]; } } for......