跳到正文

题解

CF989C 题解

Vitamin_B约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年3月26日
收录
2025年12月12日
更新
2026年11月6日
篇幅
约 2 分钟
题目
CF989C

版本

  1. v1当前

思路

把 50×5050\times50 的矩阵分割成四个 25×2525\times25 的小矩阵,分别存四个字母。然后因为方格充足,所以可以在不破坏原先 A 矩阵的情况下在其中存 d−1d-1 个 D,其余同理。因为资源充足,所以其中一种解决方案就是间隔着放字母。

代码

C++
# include <bits/stdc++.h>
using namespace std;
int a, b, c, d, x, y;
char ans[55][55];
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> a >> b >> c >> d;
	cout << "50 50";
	for (int i = 0; i < 25; ++ i)
		for (int j = 0; j < 25; ++ j)
			ans[i][j] = 'A';
	for (int i = 0; i < 25; ++ i)
		for (int j = 25; j < 50; ++ j)
			ans[i][j] = 'B';
	for (int i = 25; i < 50; ++ i)
		for (int j = 0; j < 25; ++ j)
			ans[i][j] = 'C';
	for (int i = 25; i < 50; ++ i)
		for (int j = 25; j < 50; ++ j)
			ans[i][j] = 'D';
	x = y = 1;
	while (-- d) {
		ans[x][y] = 'D';
		if ((y += 2) > 24)
			x += 2, y = 1;
	}
	x = 1, y = 26;
	while (-- c) {
		ans[x][y] = 'C';
		if ((y += 2) > 49)
			x += 2, y = 26;
	}
	x = 26, y = 1;
	while (-- b) {
		ans[x][y] = 'B';
		if ((y += 2) > 24)
			x += 2, y = 1;
	}
	x = y = 26;
	while (-- a) {
		ans[x][y] = 'A';
		if ((y += 2) > 49)
			x += 2, y = 26;
	}
	for (int i = 0; i < 50; ++ i)
		cout << '\n' << ans[i];
	return 0;
}
原文