多联骨牌的生成办法,维基上只找到固定的骨牌fix,而free的没有找到。

于是只好写个set判重的简单枚举了。

旋转的操作,可以在坐标轴上画个点,以原点为轴心,逆时针旋转90度,新的点的坐标为(-y,x)。顺时针也差不多。

反转类似。

对于操作完的骨牌,还要进行标准化,取最小的横纵坐标为参考,求出新的坐标,以便于判断。

生成所有骨牌以后,预处理一下(一顿乱搞)就好了。

#include<bits/stdc++.h>
using namespace std; #define local const int maxn = ; struct Cell
{
int x,y;
Cell(int x = ,int y = ):x(x),y(y){}
bool operator < (const Cell & rhs) const {
return x < rhs.x||(x == rhs.x && y < rhs.y);
}
};
#define FOR_CELL(c, p) for(Polyomino::const_iterator c = (p).begin(); c != (p).end(); ++c) typedef set<Cell> Polyomino; inline void normalize(Polyomino *px){
int minx = px->begin()->x, miny = px->begin()->y;
Polyomino::const_iterator c;
for(c = px->begin(); c != px->end(); ++c) {
minx = min(minx, c->x);
miny = min(miny, c->y);
}
Polyomino pn;
for(c = px->begin(); c != px->end(); ++c){
pn.insert(Cell(c->x-minx,c->y-miny));
}
*px = pn;
} inline void Rotate(Polyomino & px) {
Polyomino p2;
Polyomino::const_iterator c;
for(c = px.begin(); c != px.end(); ++c)
p2.insert(Cell(c->y,-c->x));
px = p2;
normalize(&px);
} inline void flip(Polyomino &px) {
Polyomino p3;
Polyomino::const_iterator c;
for(c = px.begin(); c != px.end(); ++c)
p3.insert(Cell(-c->x,c->y));
normalize(&p3);
px = p3;
} set<Polyomino>poly[maxn]; void check(const Polyomino &p0,Cell& newCell){
Polyomino p = p0;
p.insert(newCell);
normalize(&p);
int n = p.size();
for(int i = ; i < ; i++){
if(poly[n].count(p)) return;
Rotate(p);
}
flip(p);
for(int i = ; i < ; i++){
if(poly[n].count(p)) return;
Rotate(p);
}
poly[p.size()].insert(p);
} int ans[maxn][maxn][maxn]; struct whc
{
int w,h,c;
whc(){}
whc(int w,int h,int c):w(w),h(h),c(c){}
}; int SIZE[maxn] = {};
whc V[maxn][]; void generatePoly(){
const int dx[] = {,,,-};
const int dy[] = {,-,,};
Polyomino s;
s.insert(Cell(,));
poly[].insert(s); for(int i = ; i < maxn-; i++){
for(set<Polyomino>::iterator it = poly[i].begin(); it != poly[i].end(); it++ ){
FOR_CELL(c,*it){
for(int dir = ; dir < ; dir++){
Cell newc(c->x+dx[dir],c->y+dy[dir]);
if(it->count(newc) == ) check(*it,newc);
}
}
}
} int mp[maxn][maxn][maxn] = {};
for(int n = ; n < maxn; n++){
SIZE[n] = ;
for(set<Polyomino>::iterator it = poly[n].begin(); it != poly[n].end(); it++ ){
int maxx,maxy; maxx = maxy = ;
FOR_CELL(c,*it){
maxx = max(maxx,c->x);
maxy = max(maxy,c->y);
}
if(maxy<maxx) swap(maxx,maxy);
mp[n][maxx][maxy]++;
}
} for(int n = ; n < maxn; n++){
for(int w = ; w < n; w++)
for(int h = w; h < n; h++){
if(mp[n][w][h]){
V[n][SIZE[n]++] = whc(w,h,mp[n][w][h]);
}
}
} } inline int ANS(int n,int w,int h){
if(~ans[n][w][h]) return ans[n][w][h];
else {
int cnt = ;
whc *a = V[n];
for(int i = , sz =SIZE[n] ; i < sz; i++ ){
whc & u = a[i];
if(u.w < w && u.h < h) cnt += u.c;
}
return ans[n][w][h] = cnt;
}
} int main()
{
#ifdef local
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // local
generatePoly();
memset(ans,-,sizeof(ans));
int n,w,h;
while(~scanf("%d%d%d",&n,&w,&h)){
if(h<w) swap(w,h);
printf("%d\n",ANS(n,w,h));
}
return ;
}

UVA1602 Lattice Animals 网格动物 (暴力,STL)的更多相关文章

  1. UVA-1602 Lattice Animals 搜索问题(打表+set)

    题目链接 https://vjudge.net/problem/UVA-1602 紫书的一道例题,跟之前的很多题目有很多不同. 本题不像是一般的dfs或bfs这样的搜索套路,而是另一种枚举思路. 题意 ...

  2. UVA1602 Lattice Animals 搜索+剪枝

    题目大意 给出一个$w\times h$的网格,定义一个连通块为一个元素个数为$n$的方格的集合$A,\forall x\in A, \exists y\in A$,使得$x,y$有一条公共边.现要求 ...

  3. ACM题目————网格动物

    Lattice animal is a set of connected sites on a lattice. Lattice animals on a square lattice are esp ...

  4. 【DFS】【打表】Lattice Animals

    [ZOJ2669]Lattice Animals Time Limit: 5 Seconds      Memory Limit: 32768 KB Lattice animal is a set o ...

  5. UVA - 1602 Lattice Animals (暴力+同构判定)

    题目链接 题意:求能放进w*h的网格中的不同的n连通块个数(通过平移/旋转/翻转后相同的算同一种),1<=n<=10,1<=w,h<=n. 刘汝佳的题真是一道比一道让人自闭.. ...

  6. 网格动物UVA1602

    题目大意 输入n,w,h(1<=n<=10,1<=w,h<=n).求能放在w*h网格里的不同的n连块的个数(平移,旋转,翻转算一种) 首先,方法上有两个,一是打表,dfs构造连 ...

  7. 【例题 7-14 UVA-1602】Lattice Animals

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 借鉴网上的题解的. 思路是. 用"标准化"的思想. 确定基准点(0,0) 然后假设(0,0)是第一个连通块. 然 ...

  8. UVa 1602 Lattice Animals (STL && 生成n连块 && 无方向形状判重)

    题意 : 给定一个 w * h 的 矩阵,在矩阵中找不同n个连通块的个数(旋转,翻转,平移算作一种) 分析 : 这题的关键点有两个 ① 生成n连块并且存储起来(因为题目是多测试用例,如果每一次都重新生 ...

  9. UVA 1602 Lattice Animals

    题目 输入n.w.h($1\leqslant n \leqslant 10, 1\leqslant w,h \leqslant n$),求能放在w*h网格里的不同的n连块的个数(注意,平移.旋转.翻转 ...

随机推荐

  1. putty连接虚拟机注意事项

    1,虚拟机ssh服务要开 2,虚拟机最好把防火墙关掉 3,虚拟机和主机的IP要在同一网段 4,大哥,putty上面那个才是要连接的远程主机IP啊!下面那个是会话名,写什么都行. 5,可以选择UTF8, ...

  2. 滴滴Booster移动APP质量优化框架 学习之旅 二

    推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 续写滴滴Booster移动APP质量优化框架学习之旅,上篇文章分 ...

  3. exporting

    exporting: { buttons: { contextButton: { menuItems: [{ text: '导出png图片 100宽度', onclick: function () { ...

  4. Linux常用命令汇总(未完,待补充)

    由于工作中经常要和Linux服务器打交道,故整理了一些常用的Linux命令,方便新入职的同学或实习生参考学习. 1. 查看Linux内核版本 #uname -a 2. ctrl+insert:复制选中 ...

  5. 在VMware上克隆Linux虚拟机及其网卡配置方法

    最近在搭建Hadoop集群,1个Master,3个Workers.使用VMware workstations创建Linux虚拟机,版本是CentOS7.安装完成并做了相应的网络配置后,使用VMware ...

  6. jave (java的ffmpeg框架)简单使用

    引入文件( jave-native-win64 windows 64位系统jave-native-linux64 linux 64位系统按自己服务器系统来替换 ) <dependency> ...

  7. [题解](prufer)明明的烦恼

    https://www.cnblogs.com/noip/archive/2013/03/10/2952520.html 以及高精(抄 #include<iostream> #includ ...

  8. bzoj3295: [Cqoi2011]动态逆序对 三维数点

    为了便于考虑,把删除反序变为增加 于是就变成关于权值和位置和时间的三维数点 一波cdq一波树状数组教做人 (神TM需要longlong,80了一发) #include <bits/stdc++. ...

  9. poj3728The merchant树剖+线段树

    如果直接在一条直线上,那么就建线段树 考虑每一个区间维护最小值和最大值和答案,就符合了合并的条件,一个log轻松做 那么在树上只要套一个树剖就搞定了,多一个log也不是问题 注意考虑在树上的话每一条链 ...

  10. Selenium 开源书(一): Selenium历史

    Selenium历史 Selenium最初由Jason Huggins于2004年开发,作为ThoughtWorks的内部工具.Huggins后来加入了ThoughtWorks的其他程序员和测试人员, ...