Codeforces Round #487 (Div. 2) @989-A,B,C

A题:

http://codeforces.com/contest/989/problem/A

满足ABC三个相邻就可以.

#include <bits/stdc++.h>
typedef long long ll;
const int MAXN = 1e5 +10;

#define fastIO ios_base::sync_with_stdio(0);
using namespace std;



int main()
{

    string  str;
    cin>>str;

    int flag = 1;
    int len = str.length();
    for(int i = 0 ;i<len ;i++)
    {
        int cot = 0;
        for(int j = i ;j <i+3;j++)
        {
            if(str[j]=='A')
                cot+=1;
            else if(str[j]=='B')
                cot+=3;
            else if(str[j]=='C')
                cot+=7;
        }
        if(cot==11)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    return 0;
}

B题:

http://codeforces.com/contest/989/problem/B

i与i+p 保持不同,

当 都为. . 时 考虑 一个为0 另一个为1 

#include <bits/stdc++.h>
typedef long long ll;
const int MAXN = 1e5 +10;

#define fastIO ios_base::sync_with_stdio(0);
using namespace std;



int main()
{
    int n,p;
    string str;
    cin>>n>>p;
    cin>>str;
    int len = str.length();
    for(int i = 0 ;i<len;i++)
    {

        if(i+p>(len-1) )
            break;
        if(str[i]=='.'&&str[i+p]=='.')
        {
            str[i]='1';
            str[i+p]='0';
        }
        if(str[i]!=str[i+p])
        {
            if(str[i]=='1')
            {
                str[i+p]='0';
            }
            else if(str[i]=='0')
                str[i+p]='1';
            else if(str[i]=='.')
            {
                if(str[i+p]=='1')
                    str[i]='0';
                else if(str[i+p]=='0')
                    str[i]='1';
            }
            for(int j = 0; j<len;j++)
            {
                if(str[j]=='.')
                    str[j]='1';
            }
            cout<<str<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

C题:

http://codeforces.com/contest/989/problem/C

输出一个 n*m的 矩阵使 A的联通块为a,B为b,C为c,D为d

在 50*50 的范围内.

考虑 0-n/2  都为A    n/2 - n 都为B  在  A的范围内 填入 B和D 在 B的范围内天入A和C

#include <bits/stdc++.h>

typedef long long ll;

const int MAXN = 1e5 +20;

using namespace std;

char mp[100][100];
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int n = 50,m = 50;
    for(int i=0 ;i <n ;i++)
    {
        for(int j = 0 ; j<m;j++)
        {
            if( i>n/2)
                mp[i][j] = 'B';
            else
                mp[i][j] = 'A';
        }
    }
    a--,b--;
    for(int i = 0 ; i<n/4 ;i++)
    {
        for(int j = 0 ; j < m/2 ; j++)
        {
            if( b)
            {
                b--;
                mp[i*2][j*2] = 'B';
            }
            else if( d)
            {
                d--;
                mp[i*2][j*2] = 'D';
            }
            else
                break;
        }
        for(int j = 0 ; j < m/2 ; j++)
        {
            if( a)
            {
                a--;
                mp[ n-1-2*i][m-1-2*j] = 'A';
            }
            else if(c)
            {
                c--;
                mp[ n-1-2*i][m-1-2*j] = 'C';
            }
            else
                break;
        }
    }
    cout<<n<<" "<<m<<endl;
    for(int i = 0 ;i <n ;i++)
    {
        for(int j = 0 ; j <m ;j++)
        {
            printf("%c",mp[i][j]);
        }
        printf("\n");
    }
    return 0;
}

13

猜你喜欢

转载自blog.csdn.net/sizaif/article/details/80708562