codeforces B. Sereja and Mirroring 解题报告
题目链接:http://codeforces.com/contest/426/problem/B
题目意思:给出一个n * m的矩阵a,需要找出一个最小的矩阵b,它能通过several次的mirrorings变成a。mirrorings的操作是这样的:a的upper half(假设行是1~x)部分等于b,lower half(x+1~n部分与upper half 部分对称。对称线处于 x 和 x+1 之间。
很明显,如果矩阵a的行是奇数的话,是找不出 b 的。偶数的时候就通过比较对称的两部分是否相等来处理。
写这题是为了和参考别人的代码对比。
这是我的:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
int a[maxn][maxn];
int n, m; int check(int tn)
{
if (tn & )
return ;
int flag = ;
int half = tn / ;
for (int j = ; j <= m; j++)
{
for (int i = ; i <= half; i++)
{
if (a[i][j] != a[tn+-i][j])
{
flag = ;
break;
}
}
}
if (flag)
return ;
return ;
} int main()
{
int s, i, j;
while (scanf("%d%d", &n, &m) != EOF)
{
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
cin >> a[i][j];
}
if (check(n))
{
int tn = n / ;
while (check(tn))
{
tn /= ;
check(tn);
}
printf("%d\n", tn);
}
else
printf("%d\n", n);
}
return ;
}
参考别人代码写的:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std; typedef vector<int> vi;
typedef vector<vi> vii; int main()
{
int n, m, i, j;
while (scanf("%d%d", &n, &m) != EOF)
{
vii a(n, vi(m));
for (i = ; i < n; i++)
{
for (j = ; j < m; j++)
cin >> a[i][j];
}
bool ok = true;
int tn = n;
while (true)
{
if (tn & || !ok)
{
printf("%d\n", tn);
break;
}
tn = n;
n /= ;
for (j = ; j < m; j++)
{
for (i = ; i < n; i++)
ok &= a[i][j] == a[tn-i-][j];
}
}
}
return ;
}
codeforces B. Sereja and Mirroring 解题报告的更多相关文章
- codeforces B. Sereja and Stairs 解题报告
题目链接:http://codeforces.com/problemset/problem/381/B 题目意思:给定一个m个数的序列,需要从中组合出符合楼梯定义 a1 < a2 < .. ...
- codeforces A. Sereja and Bottles 解题报告
题目链接:http://codeforces.com/problemset/problem/315/A 题目意思:有n个soda bottles,随后给出这n个soda bottles的信息.已知第 ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
- codeforces 462C Appleman and Toastman 解题报告
题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...
随机推荐
- P3102 [USACO14FEB]秘密代码Secret Code
题目描述 Farmer John has secret message that he wants to hide from his cows; the message is a string of ...
- AtCoder Regular Contest 095E - Symmetric Grid
$n \leq 12,m \leq 12$,$n$行$m$列小写字母,现可做无数次操作:交换两行:交换两列.问是否有可能把他变成中心对称的. 没有去想分组枚举的复杂度QAQ 行和列的操作顺序是随意的. ...
- 狗书(flask基础)
为什么选择使用flask? 和其他框架相比, Flask 之所以能脱颖而出,原因在于它让开发者做主,使其能对程序具有全面的创意控制. 在 Flask 中,你可以自主选择程序的组件,如果找不到合适的,还 ...
- 清除svn检出导致的所有文件的问号
问题:将svn项目检出到桌面后,桌面的图标都有问号了,怎么消除这一大堆问号? 解决方案:(1)新建一个a.txt文件,把这行代码复制进去for /r . %%a in (.) do @if exist ...
- 浅谈云网融合与SD-WAN
一.引言 近年来,SD-WAN作为一项新技术在行业应用领域里快速发展,企业对SD-WAN的接受度日渐提升,各厂商也纷纷提出解决方案.随着全球云计算领域的活跃创新和我国云计算发展进入应用普及阶段,越来越 ...
- 输出重定向、cat、系统别名、查看指定行、时间戳
1.touch命令:如果文件不存在则创建,如存在则更新时间戳;2.除了echo有向文件写入内容的功能,cat也可以; cat > hehe # 输出重定向 cat >> hehe # ...
- luogu P1476 休息中的小呆
题目描述 当大家在考场中接受考验(折磨?)的时候,小呆正在悠闲(欠扁)地玩一个叫“最初梦想”的游戏.游戏描述的是一个叫pass的有志少年在不同的时空穿越对抗传说中的大魔王chinesesonic的故事 ...
- Codeforces 123 E Maze
Discription A maze is represented by a tree (an undirected graph, where exactly one way exists betwe ...
- ByteArrayInputStream的作用,和BufferedOutputStream 的区别
个人好奇ByteArrayInputStream,到底是有什么用于是百度了一些资料 整合了下,********这两个类对于要创建临时性文件的程序以及网络数据的传输.数据压缩后的传输等可以提高运行的的效 ...
- ubuntu uninstall postgres
Steps that worked for me on Ubuntu 8.04.2 to remove postgres 8.3 List All Postgres related packages ...