Codeforces Round #784 (Div. 4)

A. Division?

a题就是简单的if语句就好了

n = int(input())
for i in range(n):
    x = int(input())
    if x <= 1399:
        print("Division 4")
    elif x <= 1599:
        print("Division 3")
    elif x <=1899 :
        print("Division 2")
    else :
        print("Division 1")

B. Triple

这题就是给一个长度为n的序列,输出一个出现了至少三次的数,如果没有输出-1

开个桶记一下数就好了

#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
using namespace std;

const int N = 1e5+5;
int n;

int read(){
    int x = 0 , f = 1 , ch = getchar();
    while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
    if( ch == '-' ) f = -1 , ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = (x<<3)+(x<<1) + ch - '0' , ch = getchar();
    return x * f;
}

map<int,int> st;

void slove(){
    n = read() , st.clear();
    for( int i = 1 , x ; i <= n ; i ++ ){
        x = read();
        st[x] ++;
    }
    int f = -1;
    for( auto [k,v] : st )
        if( v >= 3 ){
            f = k;
        }
    printf("%d\n" , f );

}
int main()
{
    int t = read();
    while( t -- ){
        slove();
    }
	return 0;
}

C. Odd/Even Increments

给定一个数列,每次可以给奇数位或偶数位加一问是否有限次操作可以把序列变成全奇或全偶

判断一下奇数位和偶数位的奇偶性是否相等就好了

#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
using namespace std;

const int N = 105;
int n , a[N];


int read(){
    int x = 0 , f = 1 , ch = getchar();
    while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
    if( ch == '-' ) f = -1 , ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = (x<<3)+(x<<1) + ch - '0' , ch = getchar();
    return x * f;
}

map<int,int> st;

void slove(){
    n = read();
    for( int i = 1 ; i <= n ; i ++ ) a[i] = read() % 2;
    int f = 1;
    a[1] %= 2 , a[2] %= 2;
    for( int i = 3 ; i <= n && f ; i ++ ){

        if( i % 2 ){
            if( a[i] != a[1] ) f = 0 ;

        }
        else{

            if( a[i] != a[2] ) f = 0;
        }
    }
    if(f) printf("YES\n");
    else printf("NO\n");

}
int main()
{
    int t = read();
    while( t -- ){
        slove();
    }
	return 0;
}

D. Colorful Stamp

一个初始全为w的字符串,每次可以选择相邻的两位变成RBBR,现给定一个字符串,问是否能通过有限次操作得到

首先把字符串按照w分割,然后对于每一小段都必须有RB,判断一下就好

#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
using namespace std;

const int N = 105;
int n , m;


int read(){
    int x = 0 , f = 1 , ch = getchar();
    while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
    if( ch == '-' ) f = -1 , ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = (x<<3)+(x<<1) + ch - '0' , ch = getchar();
    return x * f;
}
string a , b;


void slove(){
    n = read() , b = "";
    cin >> a;
    int f = 1;
    for( int i = 0 ; i < n && f ; i ++ ){
        if( a[i] == 'W' ) continue;
        b = "";
        for( ; i < n ; i++ ){
            if( a[i] == 'W' ) break;
            b += a[i];
        }
        m = b.size();
        if( m == 1 ) f = 0;
        else {
            f = 0;
            for( int i = 1 ; i < m && !f ; i ++ ){
                if( b[i] != b[0] )
                    f = 1;
            }
        }
    }

    if(f) printf("YES\n");
    else printf("NO\n");
}
int main()
{
    int t = read();
    while( t -- ){
        slove();
    }
	return 0;
}

E. 2-Letter Strings

这道题虽然n很大,但是字母的范围只有十一种,开一个二维的数组维护一下。然后n^3的枚举一下即可

#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
using namespace std;

const int N = 15;
int n , m;
string s;
ll st[N][N];
ll res;

int read(){
    int x = 0 , f = 1 , ch = getchar();
    while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
    if( ch == '-' ) f = -1 , ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = (x<<3)+(x<<1) + ch - '0' , ch = getchar();
    return x * f;
}

void slove(){
    memset( st , 0 , sizeof(st) );
    n = read() , res = 0;
    for( int i = 1 , x , y ; i <= n ; i ++ ){
        cin >> s;
        x = s[0] -'a' , y = s[1] - 'a';
        st[x][y] ++;
    }
    for( int i = 0 ; i <= 10 ; i ++ )
        for( int j = 0 ; j <= 10 ; j ++ ){
            if(st[i][j] == 0 ) continue;
            for( int k = j+1 ; k <= 10 ; k ++ ){
                if( st[i][k] == 0 ) continue;
                res += st[i][j] * st[i][k];
            }
        }
    for( int i = 0 ; i <= 10 ; i ++ )
        for( int j = 0 ; j <= 10 ; j ++ ){
            if(st[j][i] == 0 ) continue;
            for( int k = j+1 ; k <= 10 ; k ++ ){
                if( st[k][i] == 0 ) continue;
                res += st[k][i] * st[j][i];
            }
        }
    cout << res << endl;
}
int main()
{
    int t = read();
    while( t -- ){
        slove();
    }
	return 0;
}
posted @ 2022-07-05 19:07  PHarr  阅读(28)  评论(0编辑  收藏  举报