首页 > 其他分享 >Codeforces Round #817 (Div. 4) ABCDEFG

Codeforces Round #817 (Div. 4) ABCDEFG

时间:2022-08-31 20:45:05浏览次数:92  
标签:typedef int LL cin long ABCDEFG tie Div 817

https://codeforces.com/contest/1722/problem/A

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        map<char,int> mp;
        for(int i=0;i<s.size();i++)
            mp[s[i]]++;
        if(s.size()==5&&mp['T']==1&&mp['i']==1&&mp['m']==1&&mp['u']==1&&mp['r']==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

https://codeforces.com/contest/1722/problem/B

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        string c;
        cin>>c;
        bool flag=true;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='R'&&c[i]!='R')
            {
                flag=false;
                break;
            }
            if(c[i]=='R'&&s[i]!='R')
            {
                flag=false;
                break;
            }
        }
        if(flag==false) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        s.clear();
        c.clear();
    }
    return 0;
}

https://codeforces.com/contest/1722/problem/C

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        map<string,PII> mp;
        int s1=0,s2=0,s3=0;
        for(int i=1;i<=n;i++)
        {
            string s;
            cin>>s;
            mp[s].first=1,mp[s].second=1;
            s1+=3;
        }
        for(int i=1;i<=n;i++)
        {
            string s;
            cin>>s;
            if(mp[s].first!=1)//没出现过
            {
                mp[s].first=2,mp[s].second=2;
                s2+=3;
            }
            else
            {
                mp[s].second=2;
                s1-=2;
                s2+=1;
            }
        }
        for(int i=1;i<=n;i++)
        {
            string s;
            cin>>s;
            if(mp[s].first==1&&mp[s].second==2)
            {
                s1-=1;
                s2-=1;
            }
            else if(mp[s].first==1&&mp[s].second==1)
            {
                s1-=2;
                s3+=1;
            }
            else if(mp[s].first==2&&mp[s].second==2)
            {
                s2-=2;
                s3+=1;
            }
            else s3+=3;
        }
        cout<<s1<<" "<<s2<<" "<<s3<<endl;
        mp.clear();
    }
    return 0;
}

https://codeforces.com/contest/1722/problem/D

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        s=" "+s;
        vector<LL> v;
        LL sum=0;
        for(LL i=1;i<=n;i++)
        {
            if(s[i]=='L')
            {
                LL l=i-1,r=n-i;
                sum+=l;
                if(l<r) v.push_back(r-l);
            }
            else
            {
                LL l=i-1,r=n-i;
                sum+=r;
                if(l>r) v.push_back(l-r);
            }
        }
        if(v.size()==0)
        {
            for(LL i=1;i<=n;i++)
                cout<<sum<<" ";
        }
        else
        {

        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        for(LL i=0;i<v.size();i++)
        {
            if(i==0) v[i]+=sum;
            else v[i]+=v[i-1];
            cout<<v[i]<<" ";
        }
        for(LL i=v.size()+1;i<=n;i++)
            cout<<v[v.size()-1]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

二位前缀和
https://codeforces.com/contest/1722/problem/E

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
LL a[M][M],s[M][M];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n,q;
        cin>>n>>q;
        memset(a,0,sizeof a);
        memset(s,0,sizeof s);
        for(int i=1;i<=n;i++)
        {
            LL x,y;
            cin>>x>>y;
            a[x][y]+=x*y;//面积叠加
        }
        //二维前缀和模板
        for(int i=1;i<=1000;i++)
            for(int j=1;j<=1000;j++)
            s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
        while(q--)
        {
            LL h1,w1,h2,w2;
            cin>>h1>>w1>>h2>>w2;
            //二维前缀和
            //注意不能挨着最大的外框,所以要在(h2-1,w2-1)
            cout<<s[h2-1][w2-1]-s[h1][w2-1]-s[h2-1][w1]+s[h1][w1]<<endl;
        }
    }
    return 0;
}

https://codeforces.com/contest/1722/problem/F

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
char a[M][M];
bool vis[M][M];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        memset(a,'.',sizeof a);
        memset(vis,false,sizeof vis);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            cin>>a[i][j];
        bool flag=true;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(a[i][j]=='*'&&vis[i][j]==false)
                {
                    if(a[i][j+1]=='*'&&a[i+1][j]=='*')
                    {
                        if(a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*'||a[i-1][j+2]=='*') flag=false;
                        if(a[i][j-1]=='*'||a[i][j+2]=='*') flag=false;
                        if(a[i+1][j-1]=='*'||a[i+1][j+1]=='*'||a[i+1][j+2]=='*') flag=false;
                        if(a[i+2][j-1]=='*'||a[i+2][j]=='*'||a[i+2][j+1]=='*') flag=false;

                        if(flag!=false)
                        {
                            vis[i][j]=true; vis[i][j+1]=true; vis[i+1][j]=true;
                        }
                        //else cout<<"if 111"<<endl;
                    }
                    else if(a[i][j+1]=='*'&&a[i+1][j+1]=='*')
                    {
                        if(a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*'||a[i-1][j+2]=='*') flag=false;
                        if(a[i][j-1]=='*'||a[i][j+2]=='*') flag=false;
                        if(a[i+1][j-1]=='*'||a[i+1][j]=='*'||a[i+1][j+2]=='*') flag=false;
                        if(a[i+2][j]=='*'||a[i+2][j+1]=='*'||a[i+2][j+2]=='*') flag=false;

                        if(flag!=false)
                        {
                            vis[i][j]=true; vis[i][j+1]=true; vis[i+1][j+1]=true;
                        }
                        //else cout<<"else if 222"<<endl;
                    }
                    else if(a[i+1][j]=='*'&&a[i+1][j+1]=='*')
                    {
                        if(a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*') flag=false;
                        if(a[i][j-1]=='*'||a[i][j+1]=='*'||a[i][j+2]=='*') flag=false;
                        if(a[i+1][j-1]=='*'||a[i+1][j+2]=='*') flag=false;
                        if(a[i+2][j]=='*'||a[i+2][j+1]=='*'||a[i+2][j+2]=='*') flag=false;

                        if(flag!=false)
                        {
                            vis[i][j]=true; vis[i+1][j]=true; vis[i+1][j+1]=true;
                        }
                        //else cout<<"else if 333"<<endl;
                    }
                    else if(a[i+1][j-1]=='*'&&a[i+1][j]=='*')
                    {
                        if(a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*') flag=false;
                        if(a[i][j-2]=='*'||a[i][j-1]=='*'||a[i][j+1]=='*') flag=false;
                        if(a[i+1][j-2]=='*'||a[i+1][j+1]=='*') flag=false;
                        if(a[i+2][j-2]=='*'||a[i+2][j-1]=='*'||a[i+2][j]=='*'||a[i+2][j+1]=='*') flag=false;

                        if(flag!=false)
                        {
                            vis[i][j]=true; vis[i+1][j-1]=true; vis[i+1][j]=true;
                        }
                        //else cout<<"else if 444"<<endl;
                    }
                    else
                    {
                        flag=false;
                        //if(flag==false) cout<<i<<" "<<j<<"else if 555"<<endl;
                    }
                }
            }
            if(flag==false) break;
        }
        if(flag==false) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

位运算
https://codeforces.com/contest/1722/problem/G

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
LL a[M][M],s[M][M];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        vector<LL> v(n+1,0);//长度为n+1,初始化为0的变长数组
        v[1]=1,v[2]=2;
        LL x=3;
        //定义数据时,避免过小产生重复的
        for(LL i=3;i<=n-1;i++)
        {
            v[i]=i*2;
            x^=v[i];
        }
        v[n]=x;
        for(LL i=1;i<=n;i++)
            cout<<v[i]<<" ";
        cout<<endl;
    }
    return 0;
}

标签:typedef,int,LL,cin,long,ABCDEFG,tie,Div,817
From: https://www.cnblogs.com/Vivian-0918/p/16643743.html

相关文章

  • Codeforces Round #817 (Div. 4)
    CF传送门因为洛谷题库未更新,所以给出的题面都是CF的。现场打真是太卡了(梯子挂了,codeforc.es也崩了),所以五六分钟才打开题目\(qwq\)A.SpellCheck萌萌题,把字符串放桶里......
  • Codeforces Round #817 (Div. 4)E Counting Rectangles
    CountingRectangles思维把所有的矩形左上角都叠在一起,就会发现是一个二维前缀和的求解问题:\(\sum_{i=h_s+1}^{h_b-1}\sum_{j=w_s+1}^{w_b-1}(i*j*cnt_{ij})\)这个显......
  • Python学习笔记:add、sub、mul、div、mod、pow
    一、介绍add()函数用于向调用者添加对象。使用语法为:DataFrame.add(other,axis='columns',level=None,fill_value=None)实际上等价于dataframe+other的直接使......
  • Educational Codeforces Round 133 (Rated for Div. 2) ABD
    A.2-3Moves题意:从0,每次+2-2+3-3选一个,问多少次能到n由于对称性,先让n=abs(n)0只用0次,1只用1次t=n/3;如果n%3==1,说明t-1次+3,再来一次+2,就......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    比赛链接:https://codeforces.com/contest/1721D.MaximumAND题意:给定两个序列\(a\)和\(b\),可以调整\(b\)中元素的位置,得到序列\(c\),满足\(c_i=a_i\)xor\(b......
  • Codeforces Round #287 (Div. 2) B. Amr and Pins(数学/思维)
    https://codeforces.com/contest/507/problem/B题目大意:Amr有一个半径为r、圆心在点(x,y)的圆。他希望圆心在新的位置(x',y')。在一个步骤中,Amr可以将一个大头针放在......
  • 【Virt.Contest】CF1155(div.2)
    CF传送门T1:ReverseaSubstring只有本身单调不减的字符串不能转换为字典序更小的字符串。否则肯定会出现\(s_i>s_{i+1}\)的情况。所以只要从头到尾扫一遍,找到\(s_i>......
  • Educational Codeforces Round 134 (Rated for Div. 2) A-C
    2A,C题wa2不知道为什么。B题少判一个条件:左上角A:题意有点不懂,到最后才知道是有多少种数,就输出这个种数-1即可intn,m;voidsolve(){//cin>>n>>m;chars[......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    EducationalCodeforcesRound134(RatedforDiv.2)D.MaximumAND题目大意给出序列a,b,b可以任意排列,序列c有\(c_i=a_i\bigoplusb_i\)。c序列的价值为c1&c2&c33...&......
  • Codeforces Round #816 (Div. 2)/CodeForces1715
    CodeForces1715Crossmarket解析:题目大意有一个\(n\timesm\)的空间,Stanley需要从左上角到右下角;Megan则需要从左下角到右上角。两人可以耗费\(1\)能量到达相邻......