首页 > 其他分享 >Educational Codeforces Round 153 (Rated for Div. 2)

Educational Codeforces Round 153 (Rated for Div. 2)

时间:2023-08-19 16:48:47浏览次数:39  
标签:Educational Rated const int double typedef long Codeforces define

Educational Codeforces Round 153 (Rated for Div. 2)

A - Not a Substring

思路:找到串中最大的层数,若层数为1,构造层数大于1的即可;若层数大于1,构造层数为1的即可

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=200+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    string s;cin>>s;
    if(s.size()==2&&s=="()")cout<<"No\n";
    else{
        cout<<"YES\n";
        int c=0;
        for(int j,i=0;i<s.size();++i){
            j=i;
            while(j+1<s.size()&&s[j+1]==s[i])j++;
            c=max(c,j-i+1);
            i=j;
        }
        if(c==1){
            for(int i=0;i<s.size();++i)cout<<"(";
            for(int i=0;i<s.size();++i)cout<<")";cout<<'\n';
        }else{
            for(int i=0;i<s.size();++i)cout<<"()";cout<<'\n';
        }
    }
    return;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

B - Fancy Coins

思路:要让硬币数尽可能少,那么用尽可能多的k价值的硬币;

先将m变成k的倍数,即用价值为1的普通硬币;若普通硬币不够,则用价值为1的花色硬币;

m为k的倍数后,先用普通硬币,再用价值为k的花色硬币

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=200+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    int m,k,a1,ak;
    cin>>m>>k>>a1>>ak;
    int c=m/k,z=c*k;
    int c1=min(a1,m-z),ck;
    a1-=c1,m-=c1;
    ck=min(ak,m/k);
    int ans;
    if(m%k==0)c1=min(a1/k,m/k-ck),ans=m/k-ck-c1;
    else ans=m%k+m/k-ck;
    cout<<ans<<'\n';

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

 

C - Game on Permutation

思路:要让Alice赢,即Alice下的位置前只有一个小于Alice的位置。那么可以维护前i-1个里的最小值和第二小值,当第i个数大于前i-1个数中的最小值且小于第二小值则说明Alice可以赢

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=200+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    int n;cin>>n;
    vector<int>ve(n+1);
    for(int i=1;i<=n;++i)cin>>ve[i];
    int ans=0,mi=INF,p=INF;
    for(int i=1;i<=n;++i){
        if(ve[i]>mi&&p>ve[i]){
            ans++;
            p=min(ve[i],p);
        }
        mi=min(mi,ve[i]);
    }
    cout<<ans<<'\n';
    return;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

标签:Educational,Rated,const,int,double,typedef,long,Codeforces,define
From: https://www.cnblogs.com/bible-/p/17642609.html

相关文章

  • Educational Codeforces Round 153 (Rated for Div. 2)
    EducationalCodeforcesRound153(RatedforDiv.2)这次的div2有点难度,当时b题思路对了,但是没有写好A题传送门A题意:给你一个只包含'('和')'的字符串,要求你将他的长度扩大一倍,并且使得所有括号匹配且组成的序列当中不能存在原序列的子序列A思路:这道题一开始写的时候没有注......
  • Codeforces Round 881 (Div. 3)
    比赛链接:https://codeforces.com/contest/1843A.SashaandArrayColoring题意:一个数组,可以任意分成任意组,每组的贡献是组最大值减最小值,求最大总贡献思路:一组内只有最大值和最小值有用,所以每组只由两个数组成即可,用贪心的思路,依次取出原数组的最大和最小值成组即可B.LongL......
  • Codeforces Round 893 (Div. 2)
    Preface最战俘的一场,B题写挂一发后整个人脑子就不清醒了,放着D不写去写E1,然后忘了可持久化栈有一个经典的倍增写法,最主要当时暑假前集训我还上去讲了这个东西然后比赛的时候还没想起来后面目送徐神爆切5题成功完成两场从蓝上橙,狠狠地把我这个在紫卡了半年的废物羞辱了一波不过确......
  • Educational Codeforces Round 109 (Rated for Div. 2)
    EducationalCodeforcesRound109(RatedforDiv.2)A-Potion-making思路:求最小操作数即药水最简比#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpair<int,int>PII;typedefpair......
  • Codeforces Round 883 (Div. 3)
    比赛链接:https://codeforces.com/contest/1846A.RudolphandCuttheRope题意:给n条绳子,知道一端所在高度坐标和各自绳长,他们另一端都连到一个糖果上,问至少剪掉多少绳子糖果能碰到地面思路:显然只有坐标小于绳长的才能让糖果触地,去掉其他的即可B.RudolphandTic-Tac-Toe题......
  • Codeforces Round 892 (Div. 2)
    CodeforcesRound892(Div.2)目录CodeforcesRound892(Div.2)AUnitedWeStandBOlyaandGamewithArraysCAnotherPermutationProblemDAndreyandEscapefromCapygradEMaximumMonogonosityAUnitedWeStand给定长度为\(n\)的数组a,可以将a中元素添加到空数组b......
  • 2023.08.12 codeforces round 893 div2
    年轻人的第四场div2rank:8217solved:2ratingchange:+31newrating:1354A.Buttons题意:给定a,b,c三种按钮的数量,a按钮只能被Anna按,b按钮只能被Katie按,两个人都可以按c按钮,最后没有按钮可以按的人输,Anna先手,问谁是赢家;两个人肯定优先按c按钮,且Anna是先手,只需比较两人能按的按......
  • Codeforces Round 891 (Div. 3)
    比赛链接:https://codeforces.com/contest/1857A.ArrayColoring题意:一个数列,问能否分成两个和的奇偶性相同的集合思路:因为偶数不改变奇偶性,咱们就统计奇数的个数,能平分成两组就行B.MaximumRounding题意:给一个数,每次可以找一位数不四舍可五入,然后把这个位及后面的数都变成......
  • Educational Codeforces Round 107 (Rated for Div. 2)
    EducationalCodeforcesRound107(RatedforDiv.2)A-ReviewSite思路:数1和3的个数#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpair<int,int>PII;typedefpair&l......
  • Codeforces Round 765 (Div. 2) A-E
    A.AncientCivilization好像就是对每个二进制位看一下0多还是1多,选择多的那个数就好了。vp的时候直接猜的,交了一发直接过了voidsolve(){intn=read(),m=read();vector<int>cnt0(m+1),cnt1(m+1);for(inti=1;i<=n;i++){intx=read();for(int......