Codeforces Round 914 (Div. 2)

发布时间 2023-12-11 17:58:12作者: 加固文明幻景

基本情况

A题+2,幸好后面突然悟了。

B题体现了读题以及一词多义的重要性。

C题不会。看了一下1700分的题目,暂时先放了。

A. The Third Three Number Problem

Problem - A - Codeforces

推出了规律,\(n\) 为偶数的时候,无脑 \(a = n\oplus 1, b = n\oplus 1, c = 1\) 就行。然而奇数时却死活推不出来。

后面突然想到,有没有一种可能:奇数就是无解?

然后还真是。。。

B. Almost Ternary Matrix

Problem - B - Codeforces

分析错误

先挂一下部分题面:

You are given two even integers \(n\) and \(m\). Your task is to find any binary matrix \(a\) with \(n\) rows and \(m\) columns where every cell \((i,j)\) has exactly two neighbours with a different value than \(a_{i,j}\).

想法是很接近正解的,都是想从 \(2\times 2\) 的小方阵入手搞一个构造,但没有继续想下去,要深究为什么:

  • 迷信样例,结果被第三个样例骗了,以为答案不能由小方阵无脑构成,但实际上答案不唯一,有用小方阵无脑构成的答案:

    样例:    
    1 0 1 0
    0 0 1 1
    1 1 0 0
    0 1 0 1
    另一个答案:
    1 0 0 1
    0 1 1 0
    0 1 1 0
    1 0 0 1
    
  • even我认为是“甚至”,还在想是啥意思。结果赛后看了一下,是偶数

这两个因素导致了我没有继续想下去,然后就各种玄学尝试无果了。

改正 AC

知道 \(n,m\) 为偶数之后,自己就可以做了。

因为就两个子矩形:

1 0  0 1
0 1  1 0

直接按行按列判断条件允许就填入就行。

#include<iostream>
#include<algorithm>
#include<cstring>

int matrix[3][3];
int ans[55][55];
int vis[55][55];

void close_sync()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
}

void setLine(int x, int y, bool opt)
{
	if (opt)
		matrix[1][1] = 1, matrix[1][2] = 0, matrix[2][1] = 0, matrix[2][2] = 1;
 	else
	 	matrix[1][1] = 0, matrix[1][2] = 1, matrix[2][1] = 1, matrix[2][2] = 0;
	for (int i = x * 2 - 1, cntA = 1; i <= x * 2; i++, cntA++)
	{
		for (int j = y * 2 - 1, cntB = 1; j <= y * 2; j++, cntB++)
		{
			ans[i][j] = matrix[cntA][cntB];
		}
	}
}

void solve()
{
	int n, m;
	memset(ans, 0, sizeof(ans));
	std::cin >> n >> m;
	int tn = n >> 1, tm = m >> 1;
	for (int i = 1; i <= tn; i++)
	{
		vis[i][1] = !vis[i - 1][1];
		setLine(i, 1, vis[i][1]);
		for (int j = 2; j <= tm; j++)
		{
			vis[i][j] = !vis[i][j - 1];
			setLine(i, j, vis[i][j]);	
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			std::cout << ans[i][j] << " ";
		}
		std::cout << std::endl;
	}
}

int main()
{
 	close_sync();
	int _; std::cin >> _;
	while(_--) solve();
	return 0;
}