题解:CF2094F Trulimero Trulicina
szh_AK_all · · 题解
模拟题。
首先如果
如果
Code
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int a[N], b[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
int now = 1;
if (m % k == 0) {
if (k % 2 == 0)
for (int i = 1; i <= k; i += 2)
b[i] = i + 1, b[i + 1] = i;
else {
for (int i = 1; i <= k - 3; i += 2)
b[i] = i + 1, b[i + 1] = i;
b[k - 2] = k - 1, b[k - 1] = k, b[k] = k - 2;
}
for (int i = 1; i <= n; i++) {
if (i % 2 == 1)
for (int j = 1; j <= m; j++) {
if (j % k == 0)
cout << k;
else
cout << j % k;
cout << " ";
} else {
for (int j = 1; j <= m; j++) {
if (j % k == 0)
cout << b[k];
else
cout << b[j % k];
cout << " ";
}
}
cout << "\n";
}
continue;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << now << " ";
now++;
if (now > k)
now -= k;
}
cout << "\n";
}
}
}