P11466题解
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LL long long
#define ull unsigned long long
#define N 55
const ll mod = 998244353;
const ll inf = 1e17;
const ll INF = 1e9 + 7;
const double eps = 1e-8;
const ll Mod = (1e9 + 7);
inline ll read()
{
ll f = 0, g = 1;
char ch = getchar();
while (ch < '0' || ch > '9'){if (ch == '-') g = -1; ch = getchar();}
while (ch >= '0' && ch <= '9')
f = (f << 1) + (f << 3) + (ch ^ 48), ch = getchar();
return f * g;
}
int xy[N][N];
int main()
{
int a,b,c;
cin>>a>>b>>c;
for(int i=1;i<=a;i++)
{
int start=(c-i+1+a)%a;
for(int j=1;j<=b;j++)
{
xy[i][j]=start%c+1;
start++;
}
}
cout<<a*b<<'\n';
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
cout<<i<<' '<<j<<' '<<xy[i][j]<<'\n';
}
}
}
1.先思考把三维立体二维化 x>y>z
用一个xy[N][N]数组维护, xy坐标下,我要染黑的方块对应的z坐标
2.xy数组要保证,每行每列都出现1~Z且每个位置非空。
例子:x=5,y=4,z=3
xy数组 |1|2|3|1| |:-:|:-:|:-:|:-:| |3|1|2|3| |2|3|1|2| |1|2|3|1| |3|1|2|3|