The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the required items one by one.

Soon the Hedgehog came up with a brilliant idea: instead of buying ready-made puzzles, one can take his own large piece of paper with some picture and cut it into many small rectangular pieces, then mix them and solve the resulting puzzle, trying to piece together the picture. The resulting task is even more challenging than the classic puzzle: now all the fragments have the same rectangular shape, and one can assemble the puzzle only relying on the picture drawn on the pieces.

All puzzle pieces turn out to be of the same size X × Y, because the picture is cut first by horizontal cuts with the pitch of X, then with vertical cuts with the pitch of Y. If we denote the initial size of the picture as A × B, then A must be divisible by X and B must be divisible by Y (X and Y are integer numbers).

However, not every such cutting of the picture will result in a good puzzle. The Hedgehog finds a puzzle good if no two pieces in it are the same (It is allowed to rotate the pieces when comparing them, but it is forbidden to turn them over).

Your task is to count for a given picture the number of good puzzles that you can make from it, and also to find the puzzle with the minimal piece size.

Input

The first line contains two numbers A and B which are the sizes of the picture. They are positive integers not exceeding 20.

Then follow A lines containing B symbols each, describing the actual picture. The lines only contain uppercase English letters.

Output

In the first line print the number of possible good puzzles (in other words, the number of pairs (X, Y) such that the puzzle with the corresponding element sizes will be good). This number should always be positive, because the whole picture is a good puzzle itself.

In the second line print two numbers — the sizes X and Y of the smallest possible element among all good puzzles. The comparison is made firstly by the area XY of one element and secondly — by the length X.

Examples
Input
2 4
ABDC
ABDC
Output
3
2 1
Input
2 6
ABCCBA
ABCCBA
Output
1
2 6
111
枚举边长,然后枚举每个子方块,用hash检查
#include<iostream>
#include<set>
#include<cstdio>
using namespace std;
typedef long long ll;
char board[30][30];
set<ll>used;
int A,B,ans,x,y;
bool check(int x,int y)
{
used.clear();
int t1=A/x,t2=B/y;
for(int i=1;i<=t1;i++)for(int j=1;j<=t2;j++)
{
ll temp[5];
int cnt=0;
for(int i=1;i<5;i++) temp[i]=0;
++cnt;
for(int ii=1;ii<=x;ii++)for(int jj=1;jj<=y;jj++)
{
temp[cnt]*=171;
temp[cnt]+=board[(i-1)*x+ii][(j-1)*y+jj];
}
++cnt;
for(int ii=x;ii>=1;ii--)for(int jj=y;jj>=1;jj--)
{
temp[cnt]*=171;
temp[cnt]+=board[(i-1)*x+ii][(j-1)*y+jj];
}
++cnt;
if(x==y)
{
for(int jj=y;jj>=1;jj--)for(int ii=1;ii<=x;ii++)
{
temp[cnt]*=171;
temp[cnt]+=board[(i-1)*x+ii][(j-1)*y+jj];
}
++cnt;
for(int jj=x;jj>=1;jj--)for(int ii=1;ii<=y;ii++)
{
temp[cnt]*=171;
temp[cnt]+=board[(i-1)*x+ii][(j-1)*y+jj];
}
++cnt;
}
for(int k=1;k<cnt;k++) if(used.count(temp[k])) return false;
for(int k=1;k<cnt;k++) used.insert(temp[k]);
}
return true;
}
int main()
{
cin>>A>>B;
for(int i=1;i<=A;i++)
{
for(int j=1;j<=B;j++)
cin>>board[i][j];
}
x=y=1<<10;
for(int i=A;i>=1;i--)for(int j=B;j>=1;j--)
{
if(A%i==0&&B%j==0) if(check(i,j))
{
ans++;
// cout<<i<<" "<<j<<endl;
if(i*j<x*y) {x=i;y=j;}
else if(i*j==x*y) if(i<x){x=i;y=j;}
}
}
cout<<ans<<endl;
cout<<x<<" "<<y<<endl;
return 0;
}

54B的更多相关文章

  1. ZIP压缩算法详细分析及解压实例解释

    最近自己实现了一个ZIP压缩数据的解压程序,觉得有必要把ZIP压缩格式进行一下详细总结,数据压缩是一门通信原理和计算机科学都会涉及到的学科,在通信原理中,一般称为信源编码,在计算机科学里,一般称为数据 ...

  2. Sql Server 2012新特性 Online添加非空栏位.

    我们都知道,Sql Server在一个数据量巨大的表中添加一个非空栏位是比较费心的,缺乏经验的DBA或是开发人员甚至可能鲁莽地直接添加导致阻塞相应业务,甚至可能因为资源欠缺造成实例的全局问题.当然这都 ...

  3. Moon.Orm性能报告

    以下为有网友公司的评估测试及使用规范 大家可以下载word看看 http://pan.baidu.com/s/1hquvRuc 一.和ADO.NET进行的压力测试 说明:2000并发用户,此图为一网友 ...

  4. python之路2(基础详解)

    python一切都是对象: 列子:

  5. JAVA 调用matlab 出错总结

    1.Java:Unsupported major.minor version 51.0 (unable to load class 出现该错误是由于class编译器的JDK版本高于运行期的JDK版本. ...

  6. 一种用css实现图片在父框中等比缩放并垂直居中的办法

    一个网页中往往会有很多图片,而网站的编辑上传图片时可能并不一定按照为父框设定的那个宽高来传,这样图片往往会将父框撑开或者被父框截断.一种比较好的解决的办法是这样的: HTML代码结构: <div ...

  7. Struts2+Spring3+Hibernate3+Maven构建(基于Eclipse)

    长时间不做后台了,整理一下资料,以便翻阅. Eclipse.JDK安装略…… Maven下载地址:http://maven.apache.org/download.cgi 版本比较新的Eclipse基 ...

  8. 在JasperReport中填充JavaBean(4)

    使用Parameters参数对象传递字符串的示例,本节将演示打印List接口中Userinfo.java实体类的示例,打印的数据源不是来自于Parameters对象,而是JRBeanCollectio ...

  9. Unix/Linux环境C编程入门教程(1) Solaris 11 64bit环境搭建

    Unix/Linux版本众多,我们推荐Unix/Linux初学者选用几款典型的Unix/Linux操作系统进行学习. 本文就带大家来安装Solaris 11 64位并且配置好C/C++开发环境 本文所 ...

随机推荐

  1. 当手机被PS掉,人们看到的是手中的灵魂

    Eric Pickersgill是一名摄影师,最近喜欢拍摄并记录人们使用智能手机的情景,不过不同的是,在最终作品中会将手机从人们手中PS掉,一刹那会进入一个奇怪的世界.黑白照片也极具冲击力. 每个人神 ...

  2. poj 2186 Popular Cows

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 29908   Accepted: 12131 De ...

  3. 常见HTTP状态基本解释

    本文摘自互联网,但是忘记了具体网址,请见谅 在网站建设的实际应用中,容易出现很多小小的失误,就像mysql当初优化不到位,影响整体网站的浏览效果一样,其实,网站的常规http状态码的表现也是一样,Go ...

  4. FFT的物理意义

    来源:学步园 FFT(Fast Fourier Transform,快速傅立叶变换)是离散傅立叶变换的快速算法,也是我们在数字信号处理技术中经常会提到的一个概念.在大学的理工科课程中,在完成高等数学的 ...

  5. 解析百度搜索结果链接的url,获取真正的url

    通常,在百度输入关键词搜索出现的列表页,点击目标链接,然而跳转的时候却是百度地址,经过百度解析,才真的跳到目标页面. 在SEO中,经常需要看下自己的网站排名,又不想手动每天手动去点,可用以下方法去得到 ...

  6. GIT常用命令备忘

    Git配置 git config --global user.name "storm" git config --global user.email "stormzhan ...

  7. codevs 3369 膜拜

    3369 膜拜 http://codevs.cn/problem/3369/ 题目描述 Description 神牛有很多-当然-每个同学都有自己衷心膜拜的神牛.某学校有两位神牛,神牛甲和神牛乙.新入 ...

  8. NOI2018准备 Day10

    效率低低低低低非常低!!!!!!!!!!!!!!!!!!!!!!! noi3.3 布尔表达式 做了2个晚上做不出来... 不过今晚上A了一道很水的找规律题

  9. VS改大小写的快捷键

    改成小写:Ctrl+U 改成大写:Ctrl+Shift+U 记得要选中要修改的一段英文.

  10. maven常用插件: 打包源码 / 跳过测试 / 单独打包依赖项

    一.指定编译文件的编码 maven-compile-plugin <plugin> <groupId>org.apache.maven.plugins</groupId& ...