c_cpp Google Code Jam 2018 Qual。回合,抱歉质量差的代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Google Code Jam 2018 Qual。回合,抱歉质量差的代码相关的知识,希望对你有一定的参考价值。

#include <cstdio>
#include <cstring>

int m[20][20];
int filled;

void fill(int x, int y) {
    if (m[x][y]) return;
    m[x][y] = 1;
    filled++;
    // fprintf(stderr, " - filled #%d -> (%d, %d)\n", filled, x, y);
}

int tryFill(int x, int y) {
    while (1) {
        int ok = 1;
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                if (!m[x+i][y+j]) {
                    ok = 0;
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) return 1;

        printf("%d %d\n", x, y);

        int X, Y;
        int ret = scanf("%d%d", &X, &Y);

        if (X == -1 || ret == EOF) {
            return -1;
        } else if (X == 0) {
            return 0;
        }

        fill(X, Y);
    }
}

int main() {
    setbuf(stdout, NULL);

    int T;
    scanf("%d", &T);

    while (T--) {
        int A;
        scanf("%d", &A);

        memset(&m, 0, sizeof(m));
        filled = 0;

        int bound = 17;
        if (A < 60) bound = 6;

        for (int i = 2; i < bound; i += 3) {
            for (int j = 2; j < bound; j += 3) {
                // fprintf(stderr, "*** try fill %d %d ***\n", i, j);
                int ret = tryFill(i, j);
                if (ret == 0) {
                    goto outside;
                } else if (ret < 0) {
                    return 1;
                }
            }
        }

        // exhausted but unable to convince judge; die
        printf("-1 -1\n");
        return 1;

        outside:;
    }
}
#include <cstdio>
#include <cstring>
#include <algorithm>

int arr1[50099];  // 2i
int arr2[50099];  // 2i+1

int main() {
    int T;
    scanf("%d", &T);

    for (int t = 1; t <= T; t++) {
        int N;
        scanf("%d", &N);

        for (int i = 0; i < N; i++) {
            scanf("%d", &(i % 2 == 0 ? arr1 : arr2)[i / 2]);
        }

        std::sort(arr1, arr1 + (N / 2 + N % 2));
        std::sort(arr2, arr2 + (N / 2));

        int prob = -1;
        for (int i = 0; i < N / 2; i++) {
            if (arr1[i] > arr2[i]) {  // 2i, 2i+1
                prob = i * 2;
                break;
            }
            // 2i+2 exceed N
            if (N % 2 == 0 && i == N / 2 - 1) break;
            if (arr2[i] > arr1[i + 1]) {  // 2i+1, 2i+2
                prob = i * 2 + 1;
                break;
            }
        }

        if (prob < 0) {
            printf("Case #%d: OK\n", t);
        } else {
            printf("Case #%d: %d\n", t, prob);
        }
    }
}
#include <cstdio>
#include <cstring>

int main() {
    int T;
    scanf("%d", &T);

    for (int i = 1; i <= T; i++) {
        int d;
        char s[32];
        scanf("%d%s", &d, s);
        int len = strlen(s);

        int ok = 0;
        int ans = 0;
        while (1) {
            int eff = 0;
            int mul = 0;

            for (int i = 0; i < len; i++) {
                if (s[i] == 'C') {
                    mul++;
                } else {
                    eff += 1 << mul;
                }
            }

            // printf("[%s], attk=%d\n", s, eff);

            if (eff <= d) {
                ok = 1;
                break;
            }

            int dirty = 0;
            int pos = len - 1;
            while (pos > 0) {
                if (s[pos - 1] == 'C' && s[pos] == 'S') {
                    dirty = 1;
                    s[pos - 1] = 'S';
                    s[pos] = 'C';
                    ans++;
                    break;
                }
                pos--;
            }
            if (!dirty) break;
        };

        if (ok) {
            printf("Case #%d: %d\n", i, ans);
        } else {
            printf("Case #%d: IMPOSSIBLE\n", i);
        }
    }
}

以上是关于c_cpp Google Code Jam 2018 Qual。回合,抱歉质量差的代码的主要内容,如果未能解决你的问题,请参考以下文章

Google Code Jam 2020 Qualification Round: Vestigium Solution

Google Code Jam 2020 Qualification Round: Vestigium Solution

Google Code Jam 2016 Round 1B B

Google Code Jam 2016 Round 1C C

Google Code Jam 2019 Round 1A 题解

Google Code Jam 2020 Round1B Blindfolded Bullseye