B. Sereja and Mirroring
1 second
256 megabytes
standard input
standard output
Let's assume that we are given a matrix b of size x × y,
let's determine the operation of mirroring matrix b. The mirroring of matrix b is
a2x × y matrix c which has the following
properties:
- the upper half of matrix c (rows with numbers from 1 to x)
exactly matches b; - the lower half of matrix c (rows with numbers from x + 1 to 2x)
is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1).
Sereja has an n × m matrix a. He wants to
find such matrix b, that it can be transformed into matrix a,
if we'll perform on it several(possibly zero) mirrorings. What minimum number of rows can such matrix contain?
The first line contains two integers, n and m (1 ≤ n, m ≤ 100).
Each of the next n lines contains m integers — the
elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) —
the i-th row of the matrix a.
In the single line, print the answer to the problem — the minimum number of rows of matrix b.
4 3
0 0 1
1 1 0
1 1 0
0 0 1
2
3 3
0 0 0
0 0 0
0 0 0
3
8 1
0
1
1
0
0
1
1
0
2
In the first test sample the answer is a 2 × 3 matrix b:
001
110
If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:
001
110
110
001
#include <stdio.h>
#include <stdlib.h>
#include <string.h> int num[111][111]; int main ()
{
int n,m;
scanf ("%d%d",&n,&m); int i,k; for (i = 0;i < n;i++)
for (k = 0;k < m;k++)
scanf ("%d",&num[i][k]); int ans = n;a if (n % 2)
printf ("%d\n",n);
else
{
int tn = n;
while (1)
{
int tf = 1;
for (i = 0;i < tn / 2;i++)
for (k = 0;k < m;k++)
if (num[i][k] != num[tn - 1 - i][k])
tf = 0;
if (tf)
{
if (tn % 2)
break;
tn /= 2;
}else
{
//tn *= 2;
break;
}
}
printf ("%d\n",tn);
} return 0;
}
B. Sereja and Mirroring的更多相关文章
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- CF:Problem 426B - Sereja and Mirroring 二分或者分治
这题解法怎么说呢,由于我是把行数逐步除以2暴力得到的答案,所以有点二分的意思,可是昨天琦神说是有点像分治的意思.反正总的来说:就是从大逐步细化找到最优答案. 可是昨晚傻B了.靠! 多写了点东西,然后就 ...
- codeforces B. Sereja and Mirroring 解题报告
题目链接:http://codeforces.com/contest/426/problem/B 题目意思:给出一个n * m的矩阵a,需要找出一个最小的矩阵b,它能通过several次的mirror ...
- CodeForces - 426B(对称图形)
Sereja and Mirroring Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64 ...
- Codeforces Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #243 (Div. 2) A~C
题目链接 A. Sereja and Mugs time limit per test:1 secondmemory limit per test:256 megabytesinput:standar ...
- CF380C. Sereja and Brackets[线段树 区间合并]
C. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standa ...
- T-SQL 语句创建Database的SQL mirroring关系
1 证书部分:principle 和 secondary 端执行同样操作,更改相应name即可 USE master; --1.1 Create the database Master Key, if ...
随机推荐
- (转)mysql分表的3种方法
原文:http://blog.51yip.com/mysql/949.html 一,先说一下为什么要分表 当一张的数据达到几百万时,你查询一次所花的时间会变多,如果有联合查询的话,我想有可能会死在那儿 ...
- PPT去掉图片白色背景
双击图片,点击菜单栏“删除背景”,用矩形框选中想要的区域,然后将鼠标焦点移到图片外,单击鼠标即可.
- Rhythmbox中文乱码解决的方法
转自:http://hi.baidu.com/morgensonne/item/3470aef58747abde6325d2d9 今天在网络上找到了一个比較好的解决Rhythmbox中文乱码的问题的方 ...
- JS 点击复制Copy插件--Zero Clipboard
写博客就是一周工作中遇到哪些问题,一个优点就是能够进行一个总结,另外一个优点就是下次遇到相同的问题即使那你记不住,也能够翻看你的博客攻克了.相同也能够帮到别人遇到与你一样问题的人.或者别人有比你更好的 ...
- Dynamics CRM2013 missing prvReadComplexControl privilege
左右ComplexControl 权限设置,SDK例如,在以下的说明,仅供内部使用的实体,但是你可以没有找到这个叫配置安全角色ComplexControl的东西的. 在msdn上面查下就会发现这么一段 ...
- js简单排序
简单的排序功能 HTML代码: <body> <input id="btn1" type="button" value="排序&qu ...
- WinForm的TreeView实现Win7 Areo效果
新建一个继承自TreeView的控件类,代码如下: using System; using System.Windows.Forms; using System.Drawing; using Syst ...
- Python学习笔记4(函数与模块)
1.Python程序的结构 Python的程序由包(package).模块(module)和函数组成. 模块是处理一类问题的集合,由函数和类组成. 包是由一系列模块组成的集合.包是一个完成特定任务的工 ...
- XML巩固
一.XML基础 1.XML区分大小写, 2.XML属性值必须有引号(单引双引均可) 3.XML必须有根元素 4.一些特殊字符的需要用实体引用来替换 < < 小于 > > 大于 ...
- Firebug介绍及使用技巧
一.介绍 Firebug是网页浏览器Firefox下的一款开发调试工具.安装firebug后在浏览器的插件工具栏中(上方)会有一个小甲虫的图标. F12打开和关闭Firebug窗口. 二.FireBu ...