题解:P11466 透明立方体

· · 题解

题目传送门

\texttt{Description}

给定一个 n \times m \times k 的长方体,由 n \times m \times k 个体积为 1 \times 1 \times 1 的小正方体组成。现在要将长方体的六个面全部染成黑色,求出最少的被染黑的小正方体的个数,并任意输出一种染色方案。

\texttt{Solution}

第一部分:最少个数

第二部分:方案输出

我们可以直接通过枚举行坐标和列坐标,然后算出第三维的坐标并直接输出即可。注意取模时的负数!

时间复杂度 O(n \times m),n,m \le 5 \times 10^3 都不是问题。

\texttt{Code}

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

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int n, m, k, x;
    cin >> n >> m >> k;
    cout << n * m << endl;

    for (int i = 1; i <= n; i++) {
        x = (k - i + 1 + n) % n;
        for (int j = 1; j <= m; j++) 
        cout << i << " " << j << " " << (x++) % k + 1 << endl;
    }

    return 0;
}

完结了,拜拜。