专栏文章

题解:CF426B Sereja and Mirroring

CF426B题解参与者 3已保存评论 3

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
3 条
当前快照
1 份
快照标识符
@mir4t4jd
此快照首次捕获于
2025/12/04 15:45
3 个月前
此快照最后确认于
2025/12/04 15:45
3 个月前
查看原文
建议降橙。CF 题目传送门

题意分析

注意到 n,m100n,m \le 100,所以可以直接暴力判断矩阵是不是由镜像得到的,如果是就继续判断这个矩阵的一半,当然如果行数不是偶数就可以直接退出了。

代码

CPP
#include <bits/stdc++.h>
#define ft first
#define sd second
#define endl '\n'
#define pb push_back
#define md make_pair
#define gc() getchar()
#define pc(ch) putchar(ch)
#define umap unordered_map
#define pque priority_queue
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 bint;
typedef pair<int, int> pii;
typedef pair<pii, int> pi1;
typedef pair<pii, pii> pi2;
const int INF = 0x3f3f3f3f;
inline ll read()
{
	ll res = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : f), ch = getchar();
	while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
	return res * f;
}
inline void write(ll x)
{
	if (x < 0) x = -x, pc('-');
	if (x > 9) write(x / 10);
	pc(x % 10 + '0');
}
inline void writech(ll x, char ch) { write(x), putchar(ch); }
const int N = 1e2 + 5;
char ch[N][N];
int n = read(), m = read();
bool check(int h) // 判断 h 行的矩阵是不是由镜像得到的 
{
	for (int i = 1; i <= h / 2; i++)
		for (int j = 1; j <= m; j++)
			if (ch[i][j] != ch[h - i + 1][j]) return false;
	return true;
}
int main()
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> ch[i][j];
	while (n % 2 == 0) // 如果 n 是偶数 
		if (check(n)) n /= 2; // 接着处理矩阵的一半 
		else break;
	write(n);
	return 0;
}

评论

3 条评论,欢迎与作者交流。

正在加载评论...