首页 > 其他分享 >Codeforces Round 866 (Div. 2) ABC

Codeforces Round 866 (Div. 2) ABC

时间:2023-04-17 20:56:28浏览次数:55  
标签:typedef const cout LL cin Codeforces Div 866 mex

https://codeforces.com/contest/1820

A. Yura's New Name

题目大意:

给定一个字符串,每次这个表情^^或者这个表情^_^就是合法的

问我们这个字符串至少要添加多少东西使得怎么看都是合法的?
input 
7
^______^
___^_^^^_^___^
^_
^
^_^^^^^_^_^^
___^^
_
output 
5
5
1
1
0
3
2
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e7+10,M=4023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL sum=0;
        string s;
        cin>>s;
        if(s=="^") cout<<"1"<<endl;
        else
        {
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='^') ;
            else if(s[i]=='_')
            {
                if(i==0||s[i-1]=='_') sum++;
                if(i==s.size()-1||s[i+1]=='_') sum++;
                s[i]='^';
            }
            //cout<<sum<<endl;
        }
        cout<<sum<<endl;
        }
    }
    return 0;
}

B. JoJo's Incredible Adventures

题目大意:

给定一个字符串,这个字符串每次可以从后面拉一个字符到前面形成一个新的字符串

这样每次组成的字符串就成了一个矩阵

问这个矩阵里面可以组成的最矩形面积是多少?
input 
5
0
1
101
011110
101010
output 
0
1
2
6
1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e7+10,M=4023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        LL one=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='1') one++;
        }
        if(one==s.size()) cout<<s.size()*s.size()<<endl;
        else
        {
            LL maxn=0,sum=0;
            for(int i=0;i<s.size();i++)
            {
                if(s[i]=='0') sum=0;
                else sum++;
                maxn=max(maxn,sum);
            }
            sum=0;
            for(int i=0;i<s.size();i++)
            {
                if(s[i]=='0') break;
                else sum++;
            }
            for(int i=s.size()-1;i>=0;i--)
            {
                if(s[i]=='0') break;
                else sum++;
            }
            maxn=max(maxn,sum);
            if(maxn%2==1) cout<<(maxn/2+1)*(maxn/2+1)<<endl;
            else cout<<(maxn/2)*(maxn/2+1)<<endl;
        }
    }
    return 0;
}

C. Constructive Problem

题目大意:

给定一组数据,问我们能不能改一排数据,使得刚好mex+1。
input 
4
3
1 2 1
4
0 2 2 0
4
3 2 0 2
1
0
output 
Yes
Yes
No
No

思路:如果每个数都连续且只有一个,那么必定不可能;
如果每个数连续且任意一个不只一个,就可以把这个数字改成更大的数,从而把mex变大一个;
如果当前数组中的mex+1存在,那么必须把这一排都改了,不然要么出现越来越大的mex,要么出现不变的mex,从而判断一下,满足条件(这一排之间不能出现小数被删没了的情况)即可;
如果mex+1不存在,但是比mex+1还大的数字存在,直接随便改,一个也行,几个都行。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e7+10,M=4023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
LL a[200010];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        map<LL,LL> num;
        map<LL,PII> mp;
        LL b[200010],cnt=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            num[a[i]]++;
            if(num[a[i]]==1)
            {
                b[++cnt]=a[i];
                mp[a[i]].first=i;
            }
            mp[a[i]].second=i;
        }
        LL mex=0;
        sort(b+1,b+1+cnt);
        //for(int i=1;i<=cnt;i++) cout<<b[i]<<" "; cout<<endl;
        LL idx=-1;
        for(int i=1;i<=cnt;i++)
        {
            if(b[i]==mex) mex++;
            else
            {
                idx=i;
                break;
            }
        }
        LL ans=0;
        if(idx==-1)//说明已经是顺序排列的情况
        {
            bool flag2=false;
            for(int i=1;i<=cnt;i++)
            {
                if(num[b[i]]>1)
                {
                    flag2=true;
                    break;
                }
            }
            if(flag2==false) cout<<"No"<<endl;//直接瞄准有无多余数字可供修改
            else cout<<"Yes"<<endl;
        }
        else if(idx!=-1)
        {
            ans=b[idx];
            //cout<<mex<<" "<<idx<<" "<<ans<<endl;
            if(ans-mex>=2) cout<<"Yes"<<endl;
            else
            {
                bool flag=true;
                for(int i=mp[ans].first;i<=mp[ans].second;i++)
                {
                if(a[i]<ans)
                {
                    num[a[i]]--;
                    if(num[a[i]]<=0)
                    {
                        flag=false;
                        break;
                    }
                }
                }
                if(flag==true) cout<<"Yes"<<endl;
                else cout<<"No"<<endl;
            }
        }
    }
    return 0;
}

标签:typedef,const,cout,LL,cin,Codeforces,Div,866,mex
From: https://www.cnblogs.com/Vivian-0918/p/17327456.html

相关文章

  • python报错:divide by zero encountered in log
    原因:数字太小的原因,溢出,计算过程中出现-inf,再做其他运算,结果还是-inf。当概率很小时,取对数后结果趋于负无穷大解决:改变浮点数的精度参考:(51条消息)RuntimeWarning:dividebyzeroencounteredinlog错误解决_旅途中的宽~的博客-CSDN博客......
  • Codeforces Round 832 (Div2)
    SwapGameAlice和Bob两个人在玩游戏。有一个长度为\(n\)的序列\(a\),Alice和Bob两人轮流完成一个操作,Alice先开始。每个人可以将数列的第一个数减\(1\),并将它与后面序列的一个数进行交换,如果一个人操作之前发现当前序列中的第一个数为\(0\),这个人就输了。问如果两......
  • Codeforces Round 764 (Div. 3) -- E. Masha-forgetful
    **题目大意:取去模板串中的子串可以组成一个给定的目标串,每个子串可以用无数次,输出组成的所需的串的信息题目中的取得子串必须“>=2”很好的提示了我们,想到一个式子2*x+3*y可以等于任何数,所以从之前的串都取长度为2,为3。在进行匹配。**structnode{ intl,......
  • 解决子级用css float浮动 而父级div没高度不能自适应高度
    解决子级对象使用cssfloat浮动而父级div不能自适应高度,不能被父级内容撑开解决方法,父级div没有高度解决方法。当在对象内的盒子使用了float后,导致对象本身不能被撑开自适应高度,这个是由于浮动产生原因。如何解决父div对象自适应高度,方法有三种,接下来DIVCSS5逐一介绍。方法一:对父......
  • Codeforces Round 856 (Div2)
    CountingFactorizations任何一个正整数\(m\)都可以被唯一的分解为\(p_1^{e_1}\cdotp_2^{e_2}\ldotsp_k^{e_k}\)的形式。将正整数\(m\)的唯一质数分解转化为一个长度为\(2k\)的可重集合记为\(f(m)\)。\[f(m)=\{p_1,e_1,p_2,e_2,p_3,e_3,\ldots,p_k,e_k\}\]......
  • Codeforces Round 866 (Div. 2) A~C
     这场,非常快落!是难得对中国选手友好的时间(17:05) A观察一下,发现在连续的___中插入^就好,然后特判一下首尾,发现很像小学奥数的那个植树问题哇(注意特判一下只有一个^#include<bits/stdc++.h>usingnamespacestd;voidsolve(){strings;cin>>s;intn=s.len......
  • CodeChef Starters 83 Division 1 解题报告
    CodeChefStarters83Division1题解\(\newcommand\v\mathrm\)\(\text{ByDaiRuiChen007}\)ContestLinkA.ConstructStringProblemLink题目大意给定长度为\(n\)的字符串\(S\),每次操作可以把三个相同的字符变成一个同样的字符(\(\texttt{ccc}\to\textttc\))求若......
  • Codeforces Round 628 (Div. 2) A-D
    CodeforcesRound628(Div.2)A.EhAbAnDgCdvoidsolve(){intn=read();for(inti=1;i*i<=n;i++){intg=__gcd(i,n-i);if(g*g+i*(n-i)==n*g){cout<<i<<""<<n-i<<endl;bre......
  • Codeforces Round 862 (Div. 2)
    Preface补题ing这场思路挺顺的,早上上课的时候口胡了前5题下午都一发写过了然后想了30min的F1也Rush出来了,不过F2还是有点仙的做不动A.WeNeedtheZeroSB题,首先判断是否所有数的异或和等于\(0\)若不为\(0\)且\(n\)为偶数则无解,否则答案就是这个异或和本身#include<cstdio......
  • [Educational Codeforces Round 118 (Rated for Div. 2)]题解
    A题意:给定两个数,每一个数有两个属性,第一个属性是p1,第二个属性是p2.表示这个数有p2个后缀0.这个数本身等于p1后面加p2个0.问给你两个这种数,判断大小。思路:赛场上想到的:如果最终的长度不一样,可以直接根据长度判断。如果相等,就把后缀0加上直接比较大小就可以(比较字典序的大小),但......