54B
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.
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.
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.
2 4
ABDC
ABDC
3
2 1
2 6
ABCCBA
ABCCBA
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的更多相关文章
- ZIP压缩算法详细分析及解压实例解释
最近自己实现了一个ZIP压缩数据的解压程序,觉得有必要把ZIP压缩格式进行一下详细总结,数据压缩是一门通信原理和计算机科学都会涉及到的学科,在通信原理中,一般称为信源编码,在计算机科学里,一般称为数据 ...
- Sql Server 2012新特性 Online添加非空栏位.
我们都知道,Sql Server在一个数据量巨大的表中添加一个非空栏位是比较费心的,缺乏经验的DBA或是开发人员甚至可能鲁莽地直接添加导致阻塞相应业务,甚至可能因为资源欠缺造成实例的全局问题.当然这都 ...
- Moon.Orm性能报告
以下为有网友公司的评估测试及使用规范 大家可以下载word看看 http://pan.baidu.com/s/1hquvRuc 一.和ADO.NET进行的压力测试 说明:2000并发用户,此图为一网友 ...
- python之路2(基础详解)
python一切都是对象: 列子:
- JAVA 调用matlab 出错总结
1.Java:Unsupported major.minor version 51.0 (unable to load class 出现该错误是由于class编译器的JDK版本高于运行期的JDK版本. ...
- 一种用css实现图片在父框中等比缩放并垂直居中的办法
一个网页中往往会有很多图片,而网站的编辑上传图片时可能并不一定按照为父框设定的那个宽高来传,这样图片往往会将父框撑开或者被父框截断.一种比较好的解决的办法是这样的: HTML代码结构: <div ...
- Struts2+Spring3+Hibernate3+Maven构建(基于Eclipse)
长时间不做后台了,整理一下资料,以便翻阅. Eclipse.JDK安装略…… Maven下载地址:http://maven.apache.org/download.cgi 版本比较新的Eclipse基 ...
- 在JasperReport中填充JavaBean(4)
使用Parameters参数对象传递字符串的示例,本节将演示打印List接口中Userinfo.java实体类的示例,打印的数据源不是来自于Parameters对象,而是JRBeanCollectio ...
- Unix/Linux环境C编程入门教程(1) Solaris 11 64bit环境搭建
Unix/Linux版本众多,我们推荐Unix/Linux初学者选用几款典型的Unix/Linux操作系统进行学习. 本文就带大家来安装Solaris 11 64位并且配置好C/C++开发环境 本文所 ...
随机推荐
- JavaWeb学习总结,文件上传和下载
在Web应用系统开发中,文件上传和下载功能是非常常用的功能,今天来讲一下JavaWeb中的文件上传和下载功能的实现. 对于文件上传,浏览器在上传的过程中是将文件以流的形式提交到服务器端的,如果直接使用 ...
- html页面实现自动刷新的几种方法
使用场景: 1. 页面需要定时刷新,实时加载数据(H5中的WebSocket和SSE可以实现局部刷新) 2. 一定时间之后跳转到指定页面(登录注册之类) 3. 前端开发使用伪数据调试html页面(修改 ...
- cell与cell之间的间距问题,以及section跟随屏幕滑动而滑动问题
苹果在cell与cell之间默认没有间距,这样有时候不能满足我们界面要求,所以我们就需要将cell设置为分组模式(也就是每组一行或者多行,分为n组),然后我们就可以在代理中根据自己的需求设计cell之 ...
- PAT 1007. 素数对猜想 (20)
让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数.显然有 d1=1 且对于n>1有 dn 是偶数."素数对猜想"认为"存在无穷多对相邻且 ...
- 错题724-java
1.代码片段: byte b1=1,b2=2,b3,b6; final byte b4=4,b5=6; b6=b4+b5; b3=(b1+b2); System.out.println(b3+b6); ...
- BZOJ 1010 【HNOI2008】 玩具装箱toy
Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...
- hadoop: hive 1.2.0 在mac机上的安装与配置
环境:mac OS X Yosemite + hadoop 2.6.0 + hive 1.2.0 + jdk 1.7.0_79 前提:hadoop必须先安装,且处于运行状态(伪分式模式或全分布模式均可 ...
- python数字图像处理(19):骨架提取与分水岭算法
骨架提取与分水岭算法也属于形态学处理范畴,都放在morphology子模块内. 1.骨架提取 骨架提取,也叫二值图像细化.这种算法能将一个连通区域细化成一个像素的宽度,用于特征提取和目标拓扑表示. m ...
- RelayCommand
RelayCommand Mvvm最大的特点就是分离了View和ViewModel,将数据的显示和业务逻辑分开.使用WPF的Binding,我们不仅能够 将数据从ViewModel绑定到View,同时 ...
- C#根据当前时间获取周,月,季度,年度等时间段的起止时间
最近有个统计分布的需求,需要按统计本周,上周,本月,上月,本季度,上季度,本年度,上年度等时间统计分布趋势,所以这里就涉及到计算周,月,季度,年度等的起止时间了,下面总结一下C#中关于根据当前时间获取 ...