Codeforces Round #604 (Div. 2)(A-E)

A. Beautiful String

题意:把‘?‘换成‘a‘ or ‘b‘ or ‘c‘使得相邻的两个字符不相同。

暴力枚举每个‘?‘前后。

#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
string s;
int main(){
    ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--){
        cin>>s;
        bool ok=true;
        for(int i=0;i<s.size();i++){
            if(i!=0&&s[i]==s[i-1]){
                ok=false;
                break;
            }
            if(s[i]==‘?‘){
                bool a=false,b=false,c=false;
                if(i!=0){
                    if(s[i-1]==‘a‘)a=true;
                    else if(s[i-1]==‘b‘)b=true;
                    else if(s[i-1]==‘c‘)c=true;
                }
                if(s[i+1]==‘a‘)a=true;
                else if(s[i+1]==‘b‘)b=true;
                else if(s[i+1]==‘c‘)c=true;
                if(!a)s[i]=‘a‘;
                else if(!b)s[i]=‘b‘;
                else if(!c)s[i]=‘c‘;

            }
        }
        if(!ok)cout<<"-1"<<endl;
        else cout<<s<<endl;
    }

    return 0;
}

B. Beautiful Numbers

题意:给一个1-n的序列,判断它的子串1-m的长度是否为m。

解:桶排序记录1-n在序列的位置,然后去计算1-m的长度,判断长度是否为m。

#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e5+10;
int a[MAXN];
bool vis[MAXN];
int num[MAXN];
int main(){
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int s=1;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            num[a[i]]=i;
        }
        cout<<1;
        int l=num[1],r=num[1];
        for(int i=2;i<=n;i++){
            l=min(l,num[i]);
            r=max(r,num[i]);
            if(r-l+1!=i)cout<<0;
            else cout<<1;
        }
        cout<<endl;

    }

    return 0;
}

C. Beautiful Regional Contest

题意:给出n个人的出题数量,让你安排金银铜的人数,满足:金银铜>0,银>金,铜>金,金+银+铜<=n/2

解:模拟。直接安排出题量最多的为金牌人数,第二的为银(如果没有大于金就顺延),剩下都是铜。

#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e6+10;
int a[MAXN];
int num[MAXN];
int g,s,b;
int main(){
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int m=n/2;
        g=s=b=0;
        int flag;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(i==(n/2)+1)flag=a[i];
        }
        for(int i=1;i<=n;i++){
            if(a[i]==a[1])g++;
            else break;
        }
        s=1;
        for(int i=g+2;i<=n;i++){
            if(a[i]==flag)break;
            if(a[i]==a[i-1]||s<=g)s++;
            else break;
        }
        for(int i=s+g+1;i<=n;i++){
            if(a[i]!=flag)b++;
            else break;
        }
        if((b>g&&s>g&&(s+b+g<=m)))cout<<g<<‘ ‘<<s<<‘ ‘<<b<<endl;
        else cout<<"0 0 0"<<endl;

    }

    return 0;
}

D. Beautiful Sequence

题意:给出0,1,2,3的数量,让你判断是否能排列成一个 任意相邻两个差的绝对值=1,并输出序列。

解:暴力模拟。。。。。。。。。。。。。。。直接按顺序排,0肯定跟1组合,3肯定跟2组合,其他就是1跟2组合。(写的好丑)

#include <bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a==0&&b==0&&abs(c-d)<=1){
        cout<<"YES"<<endl;
        if(c==d){
            while(c--)cout<<"2 3 ";cout<<endl;
        }
        else if(c>d){
            while(d--)cout<<"2 3 ";cout<<2<<endl;
        }else {
            cout<<"3 ";
            while(c--)cout<<"2 3 ";cout<<endl;
        }
    }
    else if(c==0&&d==0&&abs(a-b)<=1){
        cout<<"YES"<<endl;
        if(a==b){
            while(a--)cout<<"0 1 ";cout<<endl;
        }
        else if(a>b){
            while(b--)cout<<"0 1 ";cout<<0<<endl;
        }else {
            cout<<"1 ";
            while(a--)cout<<"0 1 ";cout<<endl;
        }
    }
    else if(a<=b&&d<=c){
        int t=b-a;
        int tt=c-d;
        if(t-tt==1){
            cout<<"YES"<<endl;
            cout<<1<<‘ ‘;b--;
            while(a--){
                cout<<"0 1 ";
            }
            while(tt--){
                cout<<"2 1 ";
            }
            while(d--){
                cout<<"2 3 ";
            }cout<<endl;
        }
        else if(tt-t==1){
        cout<<"YES"<<endl;
            while(a--){
                cout<<"0 1 ";
            }
            while(t--){
                cout<<"2 1 ";
            }
            while(d--){
                cout<<"2 3 ";
            }cout<<2<<endl;
        }
        else if(t==tt){
        cout<<"YES"<<endl;
            while(a--){
                cout<<"0 1 ";
            }
            while(t--){
                cout<<"2 1 ";
            }
            while(d--){
                cout<<"2 3 ";
            }cout<<endl;
        }
        else cout<<"NO"<<endl;

    }
    else cout<<"NO"<<endl;

    return 0;
}

E. Beautiful Mirrors

经典概率题,看了别人的题解有一点点理解吧。

https://www.cnblogs.com/NaVi-Awson/p/11999959.html

#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e5+10;
typedef long long ll;
const int mod=998244353;
ll a[MAXN];
ll ksm(ll x,ll y){
    ll res=1LL;
    while(y){
        if(y&1)res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res%mod;
}
//a^(p-1)=1modp
//a^(p-2)%p=1/a;
int main(){
    int n;
    cin>>n;
    ll ans=0LL;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        ans=((((ans+1LL)%mod)*100%mod)*ksm(a[i],mod-2)%mod)%mod;
    }
    cout<<ans<<endl;

    return 0;
}

原文地址:https://www.cnblogs.com/lin1874/p/12208528.html

时间: 2024-08-29 05:36:07

Codeforces Round #604 (Div. 2)(A-E)的相关文章

Codeforces Round #316 (Div. 2) (ABC题)

A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利: 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序),第一位获得胜利: 求最后选举获胜者. 思路: 直接模拟即可. 代码: /* * @author FreeWifi_novicer * language : C++/C */ #include<cstdio> #include<iostream> #include<cstring

Codeforces Round #315 (Div. 2) (ABCD题)

A. Music 题意: 一首歌长度为S秒,已经下载了T秒,下载速度为每q秒的现实时间能下载下来(q-1)秒 的歌曲.现在开始听歌,如果听到还没下载的地方就从0秒的地方开始replay,求一首歌听完需要从0秒听几次(包括一开始那次) 思路: 我们可以用路程-时间的思路来考虑这道题. 假设两位选手"播放"与"下载","播放"的起点是0m处,"下载"的起点是Tm处,终点在Sm处,"播放"的速度是1m/s,&qu

Codeforces Round #395 (Div. 2)(未完)

2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; const int N=1e4+5; inline int read()

【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)

题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,n; scanf("%d%d%d%d",&a,&b,&c,&n); int ans=n-a-b+c; if(a<c || b<c) ans=-1; if(ans>

B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)

---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper. Help Kurt find the maximum possible product of digits among all integers from 1 to n. Input

Codeforces Round #259 (Div. 2) (简单模拟实现题)

题目链接:http://codeforces.com/problemset/problem/454/A A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine

Codeforces Round #259 (Div. 2) (序列)

题目链接:http://codeforces.com/contest/454/problem/B B. Little Pony and Sort by Shift time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day, Twilight Sparkle is interested in how to sort a se

Codeforces Round #253 (Div. 1) (A, B, C)

Codeforces Round #253 (Div. 1) 题目链接 A:给定一些牌,然后现在要提示一些牌的信息,要求提示最少,使得所有牌可以被分辨出来. 思路:一共2^10种情况,直接暴力枚举,然后对于每种情况去判断,判断的时候只要两两张牌枚举出来判断即可.不得不说CF机子真心强大,2秒限制还是能跑10^8 B:给定n个发生概率,求选出其中一些事件,使得正好有一件发生的概率最大. 思路:贪心,从大到小排序概率,然后一个个概率进来判断有没有更大,有就加入该事件,没有就跳过 C:给定n个数字,要

Nastya Hasn&#39;t Written a Legend(Codeforces Round #546 (Div. 2)E+线段树)

题目链接 传送门 题面 题意 给你一个\(a\)数组和一个\(k\)数组,进行\(q\)次操作,操作分为两种: 将\(a_i\)增加\(x\),此时如果\(a_{i+1}<a_i+k_i\),那么就将\(a_{i+1}\)变成\(a_i+k_i\),如果\(a_{i+2}<a_i+k_i\),则将\(a_{i+2}\)变成\(a_{i+1}+k_{i+1}\),以此类推. 查询\(\sum\limits_{i=l}^{r}a_i\). 思路 我们首先存下\(k\)数组的前缀和\(sum1\),