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

Codeforces Round #827 (Div. 4) ABCDEFG

时间:2022-10-14 21:36:23浏览次数:75  
标签:typedef cout LL cin long ABCDEFG tie 827 Div

https://codeforces.com/contest/1742
A.Sum

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=500200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        for(int i=1;i<=3;i++)
            cin>>a[i];
        sort(a+1,a+1+3);
        if(a[1]+a[2]==a[3]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

B.Increasing

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

C.Stripes

题目不难,但是不注意理解题目意思就会有坑

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=500200,M=200;
char a[M][M];
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        for(LL i=1;i<=8;i++)
            for(LL j=1;j<=8;j++)
            cin>>a[i][j];
        bool flagr=false,flagb=false;
        for(LL i=1;i<=8;i++)
        {
            LL r=0,b=0;
            for(LL j=1;j<=8;j++)
            {
                if(a[i][j]=='R') r++;
                else if(a[i][j]=='B') b++;
            }
            if(r==8)
            {
                flagr=true;
                break;
            }
        }
        //if(flagb==true) cout<<"B"<<endl;
        if(flagr==true) cout<<"R"<<endl;
        else
        {
            for(LL j=1;j<=8;j++)
            {

            LL r=0,b=0;
            for(LL i=1;i<=8;i++)
            {
                if(a[i][j]=='R') r++;
                else if(a[i][j]=='B') b++;
            }
            if(b==8)
            {
                flagb=true;
                break;
            }
            }
            if(flagb==true) cout<<"B"<<endl;
           // if(flagr==true) cout<<"R"<<endl;
        }
    }
    return 0;
}

D.Coprime

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=500200,M=200;
LL a[N],idx[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        for(LL i=0;i<=1020;i++)
            a[i]=0,idx[i]=0;
        LL n;
        cin>>n;
        for(LL i=1;i<=n;i++)
        {
            cin>>a[i];
            idx[a[i]]=i;//记录下标
        }

            LL maxn=-1;
            for(LL i=1;i<=1000;i++)
            {
                for(LL j=1;j<=1000;j++)
                {
                    if(idx[i]!=0&&idx[j]!=0&&__gcd(i,j)==1)
                    {
                        maxn=max(maxn,idx[i]+idx[j]);
                    }
                }
            }
        cout<<maxn<<endl;
    }
    return 0;
}

E.Scuza

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=500200,M=2002;
LL a[N],b[N],sum[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        for(LL i=1;i<=n;i++)
        {
            cin>>a[i];
            b[i]=max(b[i-1],a[i]);
            sum[i]=sum[i-1]+a[i];
        }
        b[n+1]=b[n];
        sum[n+1]=sum[n];
        //for(int i=1;i<=n;i++)
        //    cout<<b[i]<<" ";
        //cout<<endl;
        while(m--)
        {
            LL x;
            cin>>x;
            LL idx=upper_bound(b+1,b+2+n,x)-b;
            cout<<sum[idx-1]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

F.Smaller

题目大意:

给定两个字符串s t,初始化长度为都是1,只包含一个‘a’;

我们会对这两个字符串进行n次操作,并且每次操作过后我们可以对这两个字符串进行任意重排;

如果可以让t字符串>s,那么就输出YES,否则输出-1。
input 
3
5
2 1 aa
1 2 a
2 3 a
1 2 b
2 3 abca
2
1 5 mihai
2 2 buiucani
3
1 5 b
2 3 a
2 4 paiu
output 
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES

自身犯了一个致命的弱点,我以为谁更长谁就赢了,一整个呆住了
————详解见代码内解析————

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=500200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        LL lens=0,lent=0;
        char maxs='a',maxt='a';
        while(n--)
        {
            LL op,k;
            string c;
            cin>>op>>k>>c;
            if(op==1)
            {
                for(LL i=0;i<c.size();i++)
                {
                    maxs=max(maxs,c[i]);
                    if(c[i]=='a') lens+=k;
                }
            }
            else if(op==2)
            {
                for(LL i=0;i<c.size();i++)
                {
                    maxt=max(maxt,c[i]);
                    if(c[i]=='a') lent+=k;
                }
            }
            if(maxt>'a') cout<<"YES"<<endl;//s以'a'开头,t以最大字母开头
            else
            {
                //s中有非'a'
                if(maxs>'a') cout<<"NO"<<endl;
                else
                {
                    //全部都是a,到了比拼长度的时候了
                    if(lens<lent) cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
            }
        }
    }
    return 0;
}

G.Orray

题目大意:

给定长度为n的数组a,让我们重新排列数组,以至于这个数组的前缀异或或的字典序最大。
input 
5
4
1 2 4 8
7
5 1 2 3 4 5 5
2
1 101
6
2 3 4 2 3 4
8
1 4 2 3 4 5 7 1
output 
8 4 2 1 
5 2 1 3 4 5 5 
101 1 
4 3 2 2 3 4 
7 1 4 2 3 4 5 1 

1e9的数据可以用32位的0和1表示完整,所以暴力循环不超过32次

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=500200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        vector<LL> a(n),vis(n);
        for(LL i=0;i<n;i++)
            cin>>a[i];
        //a从大到小
        sort(a.begin(),a.end());
        reverse(a.begin(),a.end());

        LL pre=a[0];
        vis[0]=1;//标记
        vector<LL> v;
        v.push_back(a[0]);//存储答案
        while(1)
        {
            LL flag=-1,last=pre;
            for(LL i=0;i<n;i++)
            {
                if(vis[i]) continue;//被标记过,下一个
                if((pre|a[i])>last)
                {
                    last=pre|a[i];
                    flag=i;
                }
            }
            if(flag!=-1)
            {
                v.push_back(a[flag]);
                vis[flag]=1;
                pre|=a[flag];
            }
            else break;
        }
        for(LL i=0;i<v.size();i++)
            cout<<v[i]<<" ";
        for(LL i=0;i<n;i++)
        {
            if(!vis[i]) cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

标签:typedef,cout,LL,cin,long,ABCDEFG,tie,827,Div
From: https://www.cnblogs.com/Vivian-0918/p/16793072.html

相关文章

  • Codeforces Round #827 (Div. 4)(A~G)
     A.Sum1voidsolve(){2inta[3];3for(inti=0;i<3;i++)cin>>a[i];4sort(a,a+3);5if(a[2]==a[1]+a[0])cout<<"......
  • MaoWei-2021-GeneratingSmoothPoseSequencesForDiverseHumanMotionPredition
    #GeneratingSmoothPoseSequencesforDiverseHumanMotionPrediction#paper1.paper-info1.1MetadataAuthor::[[WeiMao]],[[MiaomiaoLiu]],[[MathieuSa......
  • AtCoder Regular Contest 150 B Make Divisible 贪心 整除分块
    给出一个A和B想要找到一个X和Y使得\(A+X|B+Y\).同时使得X+Y最小求出X+Y的最小值。值域是\([1,10^9]\)直接枚举X不太行会被某种数据卡掉。考虑正解:先固定K另\(\frac{B......
  • Codeforces Round #825 (Div. 2)(补题中)
    战绩:A.MakeAEqualtoB 实际上就只有两种操作可能,一种是遇到了不同的位置直接换,一种是换出0和1一样的个数后重新排列顺序,两种操作比较最小值输出。intmain(){......
  • Codeforces Round #827 (Div. 4) A - G
    A.Sumvoidsolve(){inta[3]={};cin>>a[0]>>a[1]>>a[2];sort(a,a+3);if(a[2]==a[0]+a[1])cout<<"YES\n";elsecout<<"NO......
  • common divisor---求最大公约数
    GreatestCommonDivisor.Thegreatestcommondivisoristhelargestnumberwhichwillevenlydividetwoothernumbers.Examples:GCD(5,10)=5,thelargestnum......
  • Codeforces Round #826 (Div. 3)
    F.Multi-ColoredSegments观察:如果某个位置上有大于等于两种不同的颜色,这个位置就可以更新任何颜色的线段的答案。基于观察就可以通过模拟来解决问题了。大概就是先离......
  • 03 Quorum Queues Internals - A Deep Dive
    标题:QuorumQueuesInternals-ADeepDive原文:https://www.cloudamqp.com/blog/quorum-queues-internals-a-deep-dive.html时间:2019-04-03在本文中,我们将更详细地了解......
  • CF823div2B
    cf823div2B题目链接题目大意多组测试数据,有\(n\)个点在数轴上,他们想要集会,每个点到目标点\(y\)的时间为$$t_i+|x_i-y|$$试求所有点到\(y\)中最长时间的最小值。思路......
  • cf823div2C
    cf823div2C题目链接题目给你两个字符串\(s_1,s_2\).每次操作可以让\(s_1\)的前k个和\(s_2\)的后k个交换。询问是否可以通过多次上述操作,使得\(s_1=s_2\)。思路这种题......