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得 ...
随机推荐
- ZOJ 3306 状压dp
转自:http://blog.csdn.net/a497406594/article/details/38442893 Kill the Monsters Time Limit: 7 Seconds ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
- 微服务网关实战——Spring Cloud Gateway
导读 作为Netflix Zuul的替代者,Spring Cloud Gateway是一款非常实用的微服务网关,在Spring Cloud微服务架构体系中发挥非常大的作用.本文对Spring Clou ...
- Systemtap examples, Network - 4 Monitoring TCP Packets
http://blog.163.com/digoal@126/blog/static/16387704020131014104256627/ 例子来自tcpdumplike.stp脚本, 当tcp ...
- android 播放MP3
<?xml version="1.0" encoding="utf-8"?> <!-- 定义当前布局的基本LinearLayout --> ...
- Android L中的RecyclerView 、CardView 、Palette的使用
<Material Design>提到,Android L版本中新增了RecyclerView.CardView .Palette.RecyclerView.CardView为用于显示复杂 ...
- Android中的多线程编程(一)附源代码
Android中多线程编程:Handler类.Runnable类.Thread类之概念分析 1.Handler类: Handler是谷歌封装的一种机制:能够用来更新UI以及消息的发送和处理.Handl ...
- BUPT复试专题—图像压缩存储(2015)
题目描述 以二维数组表示图像,其值只有0.1两种,寻找两幅图像中最大的相同方阵 输入 第一行输入一个n,接下来的2n行输入两个n*n数组,寻找一个最大的m*m子区域,使得两个数组在该子区域完全相同 ...
- JS创建对象几种不同方法具体解释
1.工厂模式 弊端:没有解决对象的识别问题,即怎么知道一个对象的类型. 2.构造函数模式 与工厂模式相比: 1.没有显式的创建对象 2.直接将属性和方法赋给了this对象 3.没有return语句 要 ...
- weexpack 的 Login.vue 及 vue 的 Login.vue
1.登录页 weexpack Login.vue <!-- 登录页 --> <template> <div class="wrapper"> ...