题目链接: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. msp430项目编程35

    msp430中项目---nand接口编程35 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结

  2. Python入门--8--现在需要先学习可视化--包:easygui

    一.安装.了解easygui 下载地址:http://bbs.fishc.com/forum.php?mod=viewthread&tid=46069&extra=page%3D1%2 ...

  3. Laravel 视图中的url

    <a href="{{ url('url') }}">url</a> <a href="{{ action('StudentControll ...

  4. cmd指令

    d:  进入D盘: cd job 进入d盘名为job的文件夹:cd显示当前路径: md test创建名为test的文件夹: rd test删除名为test的文件夹: cd.>test.json创 ...

  5. (10) android控件-date

    1.TimePicker <TimePicker android:id="@+id/timePicker4" android:layout_width="wrap_ ...

  6. 存code

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...

  7. PERL 源码 大神网站

    http://blog.csdn.net/haoyujie/article/category/1187883 http://deepfuture.iteye.com/blog/816428

  8. Go -- 如何使用gcore工具获取一个core文件而不重启应用?

    问题: 当调试一个程序的时候,理想状态是不重启应用程序就获取core文件. 解决: gcore命令可以使用下面步骤来获取core文件: 1. 确认gdb软件包已经被正确安装. 2. 使用调试参数编译程 ...

  9. pycharm、idea插件代理设置,插件安装

    pycharm和idea都是intellij的,所以插件安装是设置代理方法相似, 以pycharm举例: 1.已经安装的插件列表: 2.查找要安装的插件,没有,会给出下载插件的链接地址: 3.打开链接 ...

  10. EasyDarwin开源手机直播方案:EasyPusher手机直播推送,EasyDarwin流媒体server,EasyPlayer手机播放器

    在不断进行EasyDarwin开源流媒体server的功能和性能完好的同一时候,我们也配套实现了眼下在安防和移动互联网行业比較火热的移动端手机直播方案,主要就是我们的 EasyPusher直播推送项目 ...