Educational Codeforces Round 65 (Rated for Div. 2)

时间:2022-09-12 11:25:16

A. Telephone Number

Educational Codeforces Round 65 (Rated for Div. 2)Educational Codeforces Round 65 (Rated for Div. 2)
#include <bits/stdc++.h>
using namespace std;

int T, N;
string s;

int main() {
    scanf("%d", &T);
    while(T --) {
        bool flag = true;
        scanf("%d", &N);
        cin >> s;
        if(N < 11) flag = false;
        else if(N == 11) {
            if(s[0] == '8') flag = true;
            else flag = false;
        } else {
            int temp = -1;
            for(int i = 0; i < N; i ++) {
                if(s[i] == '8') {
                    temp = i;
                    break;
                }
            }
            if(temp == -1) flag = false;
            else if(N - temp - 1 >= 10) flag = true;
            else flag = false;
        }

        if(flag) printf("YES\n");
        else printf("NO\n");

    }
    return 0;
}
View Code

B. Lost Numbers

Educational Codeforces Round 65 (Rated for Div. 2)Educational Codeforces Round 65 (Rated for Div. 2)
#include <bits/stdc++.h>
using namespace std;

int a[10] = {4, 8, 15, 16, 23, 42};
int ans[10];

int main() {
    for(int i = 1; i <= 4; i ++) {
        printf("? %d %d\n", i, i + 1);
        fflush(stdout);
        scanf("%d", &ans[i]);
    }

    do {
        if(a[1] * a[0] == ans[1] && a[2] * a[1] == ans[2] && a[3] * a[2] == ans[3] && a[4] * a[3] == ans[4])
            break;
    } while(next_permutation(a, a + 6));

    printf("!");
    for(int i = 0; i < 6; i ++)
        printf(" %d", a[i]);
    printf("\n");

    return 0;
}
View Code

C. News Distribution

Educational Codeforces Round 65 (Rated for Div. 2)Educational Codeforces Round 65 (Rated for Div. 2)
#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 10;
int N, M;
int f[maxn], cnt[maxn];

void init() {
    for(int i = 1; i <= N; i ++)
        f[i] = i;
}

int Find(int x) {
    if(f[x] != x) f[x] = Find(f[x]);
    return f[x];
}

void Merge(int x, int y) {
    int fx = Find(x);
    int fy = Find(y);
    if(fx != fy) {
        f[fx] = fy;
    }
}

int main() {
    scanf("%d%d", &N, &M);
    init();
    while(M --) {
        int K;
        scanf("%d", &K);
        if(K) {
            for(int k = 0; k < K; k ++) {
                int x;
                int st;
                scanf("%d", &x);
                if(k == 0) st = x;
                else Merge(st, x);
            }
        }
    }

    for(int i = 1; i <= N; i ++)
        cnt[Find(i)] ++;

    for(int i = 1; i <= N; i ++)
        printf("%d%s", cnt[Find(i)], i != N ? " " : "\n");

    return 0;
}
View Code

D. Bicolored RBS

Educational Codeforces Round 65 (Rated for Div. 2)Educational Codeforces Round 65 (Rated for Div. 2)
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N;
int l[maxn];
string s;

int main() {
    scanf("%d", &N);
    cin >> s;
    l[0] = 1;
    for(int i = 1; i < N; i ++) {
         if(s[i] == '(') {
                if(s[i - 1] == '(')
                    l[i] = l[i - 1] + 1;
                else l[i] = l[i - 1];
            }

         else {
            if(s[i - 1] == ')') l[i] = l[i - 1] - 1;
            else l[i] = l[i - 1];
         }
    }

    for(int i = 0; i < N; i ++) {
        if(l[i] % 2) printf("0");
        else printf("1");
    }

    printf("\n");

    return 0;
}
View Code