欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Codeforces Round #487 (Div. 2)

程序员文章站 2022-11-30 21:44:00
A. A Blend of Springtime(暴力/模拟) 题目大意 给出$n$个花,每个点都有自己的颜色,问是否存在连续大于等于三个花颜色均不相同 sol 直接模拟判断即可 #include #include using namespace std; cons ......

A. A Blend of Springtime(暴力/模拟)

题目大意

给出$n$个花,每个点都有自己的颜色,问是否存在连续大于等于三个花颜色均不相同

sol

直接模拟判断即可

Codeforces Round #487 (Div. 2)
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN  = 1001;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int a[MAXN][4];
char s[MAXN];
int main() {
    #ifdef WIN32
    //freopen("a.in", "r", stdin);
    #endif
    scanf("%s", s + 1);
    int N = strlen(s + 1);
    for(int i = 1; i <= N; i++) {
        if(s[i] == 'A') a[i - 1][1] = 1, a[i + 1][1] = 1, a[i][1] = 1;
        if(s[i] == 'B') a[i - 1][2] = 1, a[i + 1][2] = 1, a[i][2] = 1;
        if(s[i] == 'C') a[i - 1][3] = 1, a[i + 1][3] = 1, a[i][3] = 1;
    }
    for(int i = 1; i <= N; i++) {
        if(a[i][1] == 1 && a[i][2] == 1 && a[i][3] == 1) {
            puts("Yes"); return 0;
        }
    }
    puts("No");
    return 0;
}
A

B. A Tide of Riverscape(暴力/模拟)

题目大意

给定一段序列,由$“1”,“0”,“.”$组成,其中$.$代表不确定是$“1”$还是$“0”$,

给定一个$p$,问这个序列是否满足对于$i + P <= N$的$i$,存在$i$与$i+P$位置的字符不同。

sol

大力特判两个位置是否可以满足

Codeforces Round #487 (Div. 2)
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN  = 2001;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, P;
char s[MAXN];
#define GG puts("No"); return 0;
int main() {
    #ifdef WIN32
    //freopen("a.in", "r", stdin);
    #endif
    scanf("%d %d", &N, &P);
    scanf("%s", s + 1);
    bool flag = 0;
    for(int i = 1; i <= N - P; i++) {
        if(s[i] == '1') {
            if(s[i + P] == '0') {flag = 1; break;}
            if(s[i + P] == '.') {s[i + P] = '0'; flag = 1; break;}
        }
        if(s[i] == '0') {
            if(s[i + P] == '1') {flag = 1; break;}
            if(s[i + P] == '.') {s[i + P] = '1'; flag = 1; break;}
        }
        if(s[i] == '.') {
            if(s[i + P] == '1') {s[i] = '0'; flag = 1; break;}
            if(s[i + P] == '0') {s[i] = '1'; flag = 1; break;}
            if(s[i + P] == '.') {s[i] = '1'; s[i + P] = '0'; flag = 1; break;}
        }
    }
    if(flag == 0) {puts("No"); return 0;}
    for(int i = 1; i <= N; i++) {
        if(s[i] == '.') putchar('0');
        else putchar(s[i]);
    }
    return 0;
}
B

C. A Mist of Florescence(构造)

题目大意

给出四个数$a,b,c,d$,构造一个矩阵满足$“A”,"B","C","D"$对应联通块的数量为$a,b,c,d$

sol

考场上没想出来,思维太局限了,看到$n,m<=50$但是没有把它作为突破口。

正解非常刁钻,一图解千愁,不过我写的和正解不太一样,我是每三个空格放一个。

 

Codeforces Round #487 (Div. 2)
#include<cstdio>
using namespace std;
const int MAXN = 51;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int mp[MAXN][MAXN];
int color[MAXN] = {0, 0, 1, 2, 3};
char ans[MAXN] = {' ', 'A', 'B', 'C', 'D'};
int a[5];
int main() {
    #ifdef WIN32
    //freopen("a.in", "r", stdin);
    #endif
    //int a = read() - 1, b = read() - 1, c = read() - 1, d = read() - 1;
    for(int i = 1; i <= 4; i++) a[i] = read() - 1;
    for(int i = 1; i <= 4; i++) 
        for(int k = color[i] * 12 + 1; k <= color[i] * 12 + 13; k++)
            for(int j = 1; j <= 50; j++) 
                mp[k][j] = color[i] + 1;
    
    /* for(int i = 1; i <= MAXN - 1; i++, puts(""))
        for(int j = 1; j <= MAXN - 1; j++)
            printf("%d ", mp[i][j]); */
    for(int i = 1; i <= 4; i++) {
        int num = a[i];
        for(int k = color[5 - i] * 12 + 2; num > 0 && k <= color[5 - i] * 12 + 12; k++) {
            for(int j = 2 + (k & 1); num > 0 && j <= 49; j += 3)
                mp[k][j] = color[i] + 1, num--;
        }
    }
    printf("48 50\n");
    for(int i = 1; i <= 48; i++, puts(""))
        for(int j = 1; j <= 50; j++)
            putchar(ans[mp[i][j]]);
    return 0;
}
C

 

 

Codeforces Round #487 (Div. 2)

 

总结

Codeforces Round #487 (Div. 2)

Codeforces Round #487 (Div. 2)

 

又是两题滚粗,不过值得庆幸的是前两题都是1A,T3没做出来确实比较遗憾

以前从来没做过构造题也是原因之一

感觉T3这种题是有点套路的,最重要的是不要相信它给的样例!!!

然后应该把思维打开,多在宏观角度构造构造。