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 ...
随机推荐
- 使用<base target="_self" /> IE6 cann't open the Internet site 已终止操作
今日发现一个问题,我的网页需要用到<base target="_self" />,经测试IE8,9 谷歌 火狐全都正常,但是IE6 showModalDialog ...
- The account is locked
SQL> select * from v$version where rownum=1; BANNER --------------------------------------------- ...
- linux下git使用记录1 git 提交
linux下git使用记录1 浏览:985 发布日期:2013/08/08 分类:技术分享 在使用github的时候,不可避免的接触到了git,用他来更新项目,做版本控制.这里特别把常用的命令记录 ...
- Asp.net Mvc 请求是如何到达 MvcHandler的——UrlRoutingModule、MvcRouteHandler分析,并造个轮子
这个是转载自:http://www.cnblogs.com/keyindex/archive/2012/08/11/2634005.html(那个比较容易忘记,希望博主不要生气的) 前言 本文假定读者 ...
- mvc原理和mvc模式的优缺点
一.mvc原理 mvc是一种程序开发设计模式,它实现了显示模块与功能模块的分离.提高了程序的可维护性.可移植性.可扩展性与可重用性,降低了程序的开发难度.它主要分模型.视图.控制器三层. 1.模型 ...
- java web移植 遇到Project facet Java version 1.7 is not supported
在移植eclipse项目时,如果遇到 "Project facet Java version 1.7 is not supported." 项目中的jdk1.7不支持.说明项目是其 ...
- php 出现 500 Internal Server Error错误问题解决
set_time_limit(0); //设置超时时间 chmod 777 filename //设置文件权限 问题根本不在这,读取数据太多,数组是很站内存的. 内存设置大些就ok了 ini_set( ...
- Windows7上FTP服务器建立
1. FTP服务器建立 注意:千万不能使用FTP和ftp建立用户,否则无法登陆ftp服务器. 1.1本地机器上创建一个用户 这个用户是用来登录到FTP的.我的电脑右键->管理->本地用户和 ...
- Windows安装TensorFlow-Docker Installation of TensorFlow on Windows
TensorFlow是Google开发的进行Deep Learning的包,目前只是支持在Linux和OSX上运行.不过这个秋季或许就有支持Windows的版本出现了,那么对于使用Windows的开发 ...
- HTML+CSS学习
1.彻底弄懂CSS盒子模式(DIV布局快速入门) 2.在CSS中,BOX的Padding属性的数值赋予顺序为padding:10px; 四个内边距都是10px padding:5px 10px; 上下 ...