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++开发环境 本文所 ...
随机推荐
- 《MySchool数据库设计优化》内部测试
1) 在SQL Server 中,为数据库表建立索引能够( C ). A. 防止非法的删除操作 B. 防止非法的插入操作 C. 提高查询性能 D. 节约数据库的磁盘空间 解析:索引的作用是通过使用索引 ...
- dotNet开发游戏微端
需求分析 功能要求 当玩家使用不支持 unity webplayer 的浏览器进入游戏时,让玩家通过微端玩游戏. 确保微端的功能和页游戏功能一致. 大体功能就是为unity web game开发微端, ...
- Unity打包同一文件Hash不一样
问题起因 游戏开发基本都会涉及到资源版本管理及更新,本文记录我在打包过程中遇到的一小问题: 开过中常用于标记资源版本的方法有计算文件Hash.VCS的版本等. 在Unity中对同一个资源文件进行多次打 ...
- UBUNTU添加新的分辨率
首先,直接运行xrandr查看下分辨率的情况: $ xrandr Screen 0: minimum 320 x 200, current 1280 x 1024, maximum 4096 x 40 ...
- HTML DOM 元素对象
HTML DOM 元素对象 HTML DOM 节点 在 HTML DOM (Document Object Model) 中, 每个东西都是 节点 : 文档本身就是一个文档对象 所有 HTML 元素都 ...
- webstrom软件使用
很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了 选择 License server (20 ...
- Centos下Apache使用Symlink访问外部目录出现403
在Aapche 的document root 下创建软链到其他目录时, 无法从浏览器访问, 返回403错误. 主要检查两点: 1. 软链目标目录的每一级, 都要对所有人开放执行权限, 即对各级目录 c ...
- EEG montage
Source: WikiPedia - Electroencephalography Since an EEG voltage signal represents a difference betwe ...
- GT考试(bzoj 1009)
Description 阿申准备报名参加GT考试,准考证号为N位数X1X2....Xn(0<=Xi<=9),他不希望准考证号上出现不吉利的数字.他的不吉利数学A1A2...Am(0< ...
- hadoop资料收集
大数据时代——为什么用hadoop hadoop应用场景 Hadoop一般用在哪些业务场景? Hadoop虽然强大,但不是万能的