Codeforces Round #827 (Div. 4) ABCDEFG

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;
}
posted @ 2022-10-14 21:24  高尔赛凡尔娟  阅读(29)  评论(0编辑  收藏  举报