UVA1602 Lattice Animals 网格动物 (暴力,STL)
多联骨牌的生成办法,维基上只找到固定的骨牌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)的更多相关文章
- UVA-1602 Lattice Animals 搜索问题(打表+set)
题目链接 https://vjudge.net/problem/UVA-1602 紫书的一道例题,跟之前的很多题目有很多不同. 本题不像是一般的dfs或bfs这样的搜索套路,而是另一种枚举思路. 题意 ...
- UVA1602 Lattice Animals 搜索+剪枝
题目大意 给出一个$w\times h$的网格,定义一个连通块为一个元素个数为$n$的方格的集合$A,\forall x\in A, \exists y\in A$,使得$x,y$有一条公共边.现要求 ...
- ACM题目————网格动物
Lattice animal is a set of connected sites on a lattice. Lattice animals on a square lattice are esp ...
- 【DFS】【打表】Lattice Animals
[ZOJ2669]Lattice Animals Time Limit: 5 Seconds Memory Limit: 32768 KB Lattice animal is a set o ...
- UVA - 1602 Lattice Animals (暴力+同构判定)
题目链接 题意:求能放进w*h的网格中的不同的n连通块个数(通过平移/旋转/翻转后相同的算同一种),1<=n<=10,1<=w,h<=n. 刘汝佳的题真是一道比一道让人自闭.. ...
- 网格动物UVA1602
题目大意 输入n,w,h(1<=n<=10,1<=w,h<=n).求能放在w*h网格里的不同的n连块的个数(平移,旋转,翻转算一种) 首先,方法上有两个,一是打表,dfs构造连 ...
- 【例题 7-14 UVA-1602】Lattice Animals
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 借鉴网上的题解的. 思路是. 用"标准化"的思想. 确定基准点(0,0) 然后假设(0,0)是第一个连通块. 然 ...
- UVa 1602 Lattice Animals (STL && 生成n连块 && 无方向形状判重)
题意 : 给定一个 w * h 的 矩阵,在矩阵中找不同n个连通块的个数(旋转,翻转,平移算作一种) 分析 : 这题的关键点有两个 ① 生成n连块并且存储起来(因为题目是多测试用例,如果每一次都重新生 ...
- UVA 1602 Lattice Animals
题目 输入n.w.h($1\leqslant n \leqslant 10, 1\leqslant w,h \leqslant n$),求能放在w*h网格里的不同的n连块的个数(注意,平移.旋转.翻转 ...
随机推荐
- Codeforces631C【栈维护+瞎搞】
题意: 百度. 思路: 如果该查询的R比前面的所有都大,那么前面所有都失效. 那么我先预处理出这些有效的. 那最坏的情况不就是栈里面元素(R)很多 n,n-1,n-2,n-3,n-4而且都是相反排序的 ...
- Spark HA 配置中spark.deploy.zookeeper.url 的意思
Spark HA的配置网上很多,最近我在看王林的Spark的视频,要付费的.那个人牛B吹得很大,本事应该是有的,但是有本事,不一定就是好老师.一开始吹中国第一,吹着吹着就变成世界第一.就算你真的是世界 ...
- [Xcode 实际操作]七、文件与数据-(8 )读取和解析Plist文件(属性列表文件)
目录:[Swift]Xcode实际操作 本文将演示如何读取和解析Plist文件,即属性列表文件. 它是用来存储,串行化后的对象的文件. 在项目名称上点击鼠标右键,弹出右键菜单, 选择[New File ...
- jmter介绍及安装
一. Apache JMeter介绍 1. Apache JMeter是什么 Apache JMeter 是Apache组织的开放源代码项目,是一个100%纯Java桌面应用,用于压力 ...
- 聊聊 Laravel 5.5 的 「自动发现」
ThinkSNS是什么? ThinkSNS(简称TS),一款全平台综合性社交系统,目前最新版本为ThinkSNS+.ThinkSNS V4 ThinkSNS[简]. 看了Taylor Otwell发表 ...
- visdom可视化pytorch训练过程
一.前言 在深度学习模型训练的过程中,常常需要实时监听并可视化一些数据,如损失值loss,正确率acc等.在Tensorflow中,最常使用的工具非Tensorboard莫属:在Pytorch中,也有 ...
- os.walk详解
https://www.jianshu.com/p/bbad16822eab python中os.walk是一个简单易用的文件.目录遍历器,可以帮助我们高效的处理文件.目录方面的事情. 1.载入 要使 ...
- [软件工程基础]2017.11.05 第九次 Scrum 会议
具体事项 项目交接燃尽图 每人工作内容 成员 已完成的工作 计划完成的工作 工作中遇到的困难 游心 #10 搭建可用的开发测试环境:#9 阅读分析 PhyLab 后端代码与文档:#8 掌握 Larav ...
- uoj207共价大爷游长沙
话说我可能还没有调出魔法森林呢...说好的lct第一题呢... 又是一个随机化的方法,毕竟又是判定性的问题 上次是判断无向图联通 这次是判断一些路径是否经过一条定边 若把路径上的边全部异或上一个路径的 ...
- php:封装了个时间函数,返回类似“1分钟前发布”,“5小时前发布”,“3年前发布”
处理和时间有关的时候,像发布问题等通常不会用date格式的时间,而是用类似"3分钟前发布"等格式,下面封装的php函数就可以使用: 注意:当有用到strtotime()函数的记得加 ...