【LGR-142-Div.4】洛谷入门赛 #13 赛后总结

· · 个人记录

A.魔方

目测入门 -,就是需要开long long

//1
#include<bits/stdc++.h>

typedef long long valueType;

int main() {
    valueType N;

    std::cin >> N;

    std::cout << 8 << ' ' << (12 * (N - 2)) << ' ' << (6 * (N - 2) * (N - 2)) << std::flush;

    return 0;
}

B.教学楼

突然想起来刚学OI的时候三个数排序手打 6 个if,,,

//2
#include<bits/stdc++.h>

int main() {
    int n, a, b, c;

    std::cin >> n >> a >> b >> c;

    if(std::min({a, b, c}) == a && n <= 3)
        std::cout << "library" << std::flush;
    else if(std::min({b, c}) == b && n <= 5)
        std::cout << "comprehensive" << std::flush;
    else if(n <= 9)
        std::cout << "art" << std::flush; 

    return 0;
}

C.课桌

ans = n \times x + \sum_{i = 1}^{n}a_i
//3
#include<bits/stdc++.h>

int main() {
    long long n, x;

    std::cin >> n >> x;

    long long result = n * x;

    for(int i = 1; i <= n; ++i) {
        int t;

        std::cin >> t;

        result += t;
    }

    std::cout << result << std::flush;
}

D.教室

定义教室学生总数为 s,则

s = \sum_{i = 1}^{n}{a_i \times b_i \times c_i}

还需要注意如果整除的话,最后一排人数是 m。

//4
#include<bits/stdc++.h>

int main() {
    long long n, m;

    std::cin >> n >> m;

    long long sum = 0;

    for(int i = 1; i <= n; ++i) {
        long long a, b, c;

        std::cin >> a >> b >> c;

        sum += a * b * c;
    }

    std::cout << (long long)(std::ceil((double)sum / m)) << ' ' << (long long)((sum % m == 0 ? m : sum % m)) << std::flush;
}

E.信

模拟。

//5
#include<bits/stdc++.h>

int main() {
    long long n, x, y, a, b;

    std::cin >> n >> x >> y >> a >> b;

    long long t = 0, sum = 0, max = INT_MIN;

    for(int i = 1; i <= n; ++i) {
        int S, s, M;

        std::cin >> S >> s >> M;

        int const M0 = S * x + y * s;

        if(M == M0) {
            t = std::min(t - 1, (long long)-1);

            if(t <= -b) {
                sum = std::floor(sum / 2.0);
            }
        } else {
            sum += (M - M0);

            if(M > 2 * M0) {
                sum += std::ceil((M - M0) / 2.0);
            }

            t = std::max(t + 1, (long long)1);

            if(t >= a) {
                sum <<= 1;
            }
        }

        max = std::max(max, sum);
    }

    std::cout << max << ' ' << sum << std::flush;
}

F.纸条

不会。

G.棋

直接 \mathcal{O}(NM) 暴力判断有没有人胜利即可,需要注意数组越界和连续五个 ~。

//7
#include<bits/stdc++.h>

int main() {
    int n, m;

    std::cin >> n >> m;

    std::vector<std::vector<char>> source;

    source.resize(n + 200, std::vector<char>(m + 200));

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            std::cin >> source[i][j];

    std::function<bool(int, int)> check = [&source, n, m] (int i, int j) {
        char const now = source[i][j];

        if(now != '*' && now != '$')
            return false;

        if(i - 4 >= 1)
            if(source[i - 4][j] == now && source[i - 3][j] == now && source[i - 2][j] == now && source[i - 1][j] == now)
                return true;

        if(i + 4 <= n)
            if(source[i + 4][j] == now && source[i + 3][j] == now && source[i + 2][j] == now && source[i + 1][j] == now)
                return true;

        if(j - 4 <= n)
            if(source[i][j - 4] == now && source[i][j - 3] == now && source[i][j - 2] == now && source[i][j - 1] == now)
                return true;

        if(j + 4 <= n)
            if(source[i][j + 4] == now && source[i][j + 3] == now && source[i][j + 2] == now && source[i][j + 1] == now)
                return true;

        if(i - 4 >= 1 && j - 4 >= 1)
            if(source[i - 4][j - 4] == now && source[i - 3][j - 3] == now && source[i - 2][j - 2] == now && source[i - 1][j - 1] == now)
                return true;

        if(i - 4 >= 1 && j + 4 <= m)
            if(source[i - 4][j + 4] == now && source[i - 3][j + 3] == now && source[i - 2][j + 2] == now && source[i - 1][j + 1] == now)
                return true;

        if(i + 4 <= n && j - 4 >= 1)
            if(source[i + 4][j - 4] == now && source[i + 3][j - 3] == now && source[i + 2][j - 2] == now && source[i + 1][j - 1] == now)
                return true;

        if(i + 4 <= n && j + 4 <= m)
            if(source[i + 4][j + 4] == now && source[i + 3][j + 3] == now && source[i + 2][j + 2] == now && source[i - 1][j + 1] == now)
                return true;

        return false;
    };

    int his = 0, her = 0;

    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            if(source[i][j] == '*')
                ++her;
            else if(source[i][j] == '$')
                ++his;

            if(check(i, j)) {
                std::cout << (source[i][j] == '*' ? "Pleasing!" : "zylwins!") << std::flush;

                return 0;
            }
        }
    }

    if(his == her)
        std::cout << "W" << std::flush;
    else if(her == his + 1)
        std::cout << "Z" << std::flush;
}

H.演唱会

到这里精神状态不佳,瞎打一通交上去发现有点分就不想动了。

I.std::cerr

第一题可以看出程序在 b = c - 1 的情况下会炸,(那个 -1 的锅)。

第二题通过通读题面和平日教训可以利用每次匹配成功在标准错误流输出的特点令其超时。

#include <iostream>

int main() {
    int taskId;

    std::cin >> taskId;

    if (taskId == 1) {
        std::cout << "1 2 3" << std::endl;
    } else if (taskId == 2) {

        int const t = 2e5;

        std::cout << t << std::endl;

        for(int i = 1; i <= t; ++i)
            std::cout << "std::cerr\n";
    }
}