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 ...
随机推荐
- 从手工测试逆袭为NB自动化测试的学习路线
在开始之前先学习两个工具商业web自动化测试工具请学习QTP:QTP的学习可以跳过,我是跳过了的.开源web自动化测试工具请学习Selenium:我当年是先学watir,再学selenium 这里主要 ...
- java 集合专练
handsomecui的blog地址为:http://www.cnblogs.com/handsomecui/ 本人网站为:handsomecui.top 引言:本次主要练习单列集合:Collecti ...
- java BingInteger生成2进制String循环移位时长度自动缩减
最近在做文本处理,使用MD5 生成一段文字的MD5哈希长度为32位也即128个0-1序列. 由于需要对这个MD5值进行循环移位,显然普通的 int 是不行的,所以使用 BigInteger.但是在使 ...
- iOS tableView的图片缓存异步载入
1.建立一个viewController. .h文件实现UIScrollViewDelegate和UITableViewDelegate,并声明ICTableViewDelegate(用来实现图片有缓 ...
- poj1562--Oil Deposits
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- github使用-知乎的某小姐的一篇文章
作者:珊姗是个小太阳链接:http://www.zhihu.com/question/20070065/answer/79557687来源:知乎著作权归作者所有,转载请联系作者获得授权. 作为一个文科 ...
- 怎么使用jQuery在DIV适应屏幕大小一直居中
js的代码是这样的: $(function(){ $(window).resize(function(){ $(".login").css({ position: "ab ...
- asp.net利用Ajax和Jquery在前台向后台传参数并返回值
1----------前台 首先需要 Jquer的包 <script src="js/jquery-1.9.1.js" type="text/javascript& ...
- [转载]一个小例子介绍Obj-C的函数命名方式
原文链接:http://www.cnblogs.com/liufan9/archive/2013/04/02/2995626.html 对于以前做C#或者JAVA开发的朋友而言,初次接触iOS开发,O ...
- 初学者的jquery登录注册和弹窗设计
初次学习前端,接触到jquery,写了一个简单的注册账号, 并判断输入内容是否符合命名规则的页面效果如下: 首先创建html,js文件 在做页面布局之前还要连接js文件,然后开始布局自己的页面效果 i ...