题解:ARC225 - A
题面:Four Coloring。
解题思路
虽然是道构造题,但是比想象中的要简单。
由于题目中 中相邻格子的权值由 的决定,又因为题目中给出了 中相邻格子颜色不同这一条件,同时 中的权值只能为 ,那么可以想到直接构造一个序列 ,由 的权值 直接对应 的权值 。
即:对于任意 ,;对于任意 ,。对这个进行一次暴力枚举,很容易得到 这个序列。
最后根据此序列进行输入输出即可,在输入 时,直接输出 即可。
代码实现
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <atcoder/all>
#define endl '\n'
using namespace std;
typedef long long ll;
int main(int argc, char* argv[]) {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin >> n;
array<int, 5> res = { 0, 2, 4, 1, 3 }; // res[0] 进行占位
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int x; cin >> x;
cout << res[x] << ' ';
}
cout << endl;
}
return 0;
}