题目链接: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 解题报告的更多相关文章

  1. codeforces B. Sereja and Stairs 解题报告

    题目链接:http://codeforces.com/problemset/problem/381/B 题目意思:给定一个m个数的序列,需要从中组合出符合楼梯定义 a1 < a2 < .. ...

  2. codeforces A. Sereja and Bottles 解题报告

    题目链接:http://codeforces.com/problemset/problem/315/A 题目意思:有n个soda bottles,随后给出这n个soda bottles的信息.已知第 ...

  3. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  4. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

  5. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  6. codeforces 507B. Amr and Pins 解题报告

    题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...

  7. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

  8. codeforces B. Xenia and Ringroad 解题报告

    题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...

  9. codeforces 462C Appleman and Toastman 解题报告

    题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...

随机推荐

  1. 【BZOJ2002】弹飞绵羊(LCT)

    题意:给定一棵树,要求维护以下操作: 1.删除连接(x,y)的边 2.将(x,y)之间连边 3.询问某点子树大小 对于100%的数据n<=200000,m<=100000 思路:第一道有加 ...

  2. KJ面试

    1.css input checkbox和radio样式美化 <span class="pay_list_c1 on"> <input type="ra ...

  3. Redis数据结构之整数集合

    整数集合是Redis用于保存整数值的集合抽象数据结构,它可以保存类型为int16_t .int32_t或者int64_t的整数值,并且保证集合中不会出现重复元素. 一.整数集合数据结构定义 参数说明: ...

  4. .Net Core下使用RabbitMQ比较完备的两种方案(虽然代码有点惨淡,不过我会完善)

    一.前言     上篇说给大家来写C#和Java的方案,最近工作也比较忙,迟到了一些,我先给大家补上C#的方案,另外如果没看我上篇博客的人最好看一下,否则你可能看的云里雾里的,这里我就不进行具体的方案 ...

  5. 【hibernate spring data jpa】执行了save()方法 sql语句也执行了,但是数据并未插入数据库中

    执行了save()方法  sql语句也执行了,但是数据并未插入数据库中 解决方法: 是因为执行了save()方法,也执行了sql语句,但是因为使用的是 @Transactional 注解,不是手动去提 ...

  6. HDU1800 Flying to the Mars 【贪心】

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. BUPT复试专题—最小距离查询(2013)

    题目描述 给定一个由小写字母a到z组成的字符串S,其中第i个字符为S[i](下标从0开始).你需要完成下面两个操作:INSERT c  其中c是一个待输入的字符.你需要在字符串的末尾添加这个字符.保证 ...

  8. STL algorithm算法max,max_elements(33)

    max原型: std::max C++98 C++11 C++14 default (1) template <class T> const T& max (const T& ...

  9. 软件系统架构 https://www.lanhusoft.com/Article/349.html

    跟蓝狐学习Nop--NopCommerce源码架构详解专题目录 Posted By : 蓝狐 Updated On : 2018-04-16 14:46 我们承接以下nop相关的业务,欢迎联系我们. ...

  10. mybatis 动态curd

    xml <select id="selectByCondition" parameterType="com.oracle.pojo.Student" re ...