UVA1602
实现的细节很多,学到了如何翻转、旋转、平移,get很多技巧,值得一做。
AC代码:
#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
const int maxn=10+5;
int ans[maxn][maxn][maxn];
struct animal{
int x,y;
animal(int x=0,int y=0):x(x),y(y){};
bool operator < (const animal &p) const {
return x<p.x||(x==p.x&&y<p.y);
}
};
typedef set<animal> node;
#define For_animal(c,p) for(node::iterator c=(p).begin();c!=(p).end();++c)
inline node normalize(const node &p){ //normalize
int minx=p.begin()->x,miny=p.begin()->y;
For_animal(c,p){
minx=min(minx,c->x);
miny=min(miny,c->y);
}
node p2;
For_animal(c,p){
p2.insert(animal(c->x-minx,c->y-miny));
}
return p2;
}
inline node rotate(const node &p){ //rotate
node p2;
For_animal(c,p){
p2.insert(animal(c->y,-c->x));
}
return normalize(p2);
}
inline node flip(const node &p){ //flip
node p2;
For_animal(c,p){
p2.insert(animal(c->x,-c->y));
}
return normalize(p2);
}
const int dx[] = {-1,1,0,0};
const int dy[] = {0,0,-1,1};
set<node>poly[maxn];
void add(const node &p0,const animal &newc){ //add
node p=p0;
p.insert(newc);
p=normalize(p);
int n=p.size();
for(int i=0;i<4;++i){
if(poly[n].count(p)!=0) return;
p=rotate(p);
}
p=flip(p);
for(int i=0;i<4;++i){
if(poly[n].count(p)!=0) return;
p=rotate(p);
}
poly[n].insert(p);
}
void solve(){
node s;
s.insert(animal(0,0));
poly[1].insert(s);
for(int n=2;n<=10;++n){
for(set<node>::iterator p=poly[n-1].begin();p!=poly[n-1].end();++p){
For_animal(c,*p) //从当前联通块开始延伸
for(int dir=0;dir<4;++dir){
int newx=c->x+dx[dir],newy=c->y+dy[dir];
animal newc(newx,newy);
if(p->count(newc)==0) add(*p,newc);
}
}
}
//make answer into array
const int len=10;
for(int n=1;n<=len;++n)
for(int w=1;w<=len;++w)
for(int h=1;h<=len;++h){
int cnt=0;
for(set<node>::iterator p=poly[n].begin();p!=poly[n].end();++p){
int maxx=0,maxy=0;
For_animal(c,*p){
maxx=max(maxx,c->x);
maxy=max(maxy,c->y);
}
if(min(maxx,maxy)<min(w,h)&&max(maxx,maxy)<max(w,h)) //这个地方是<而不是<=的原因是坐标是从0开始
++cnt;
}
ans[n][w][h]=cnt;
}
}
int main(){
solve();
int n,w,h;
while(scanf("%d%d%d",&n,&w,&h)==3){
printf("%d\n",ans[n][w][h]);
}
return 0;
}
如有不当之处欢迎指出!
UVA1602的更多相关文章
- UVA-1602 Lattice Animals 搜索问题(打表+set)
题目链接 https://vjudge.net/problem/UVA-1602 紫书的一道例题,跟之前的很多题目有很多不同. 本题不像是一般的dfs或bfs这样的搜索套路,而是另一种枚举思路. 题意 ...
- UVA1602 Lattice Animals 网格动物 (暴力,STL)
多联骨牌的生成办法,维基上只找到固定的骨牌fix,而free的没有找到. 于是只好写个set判重的简单枚举了. 旋转的操作,可以在坐标轴上画个点,以原点为轴心,逆时针旋转90度,新的点的坐标为(-y, ...
- UVA1602 Lattice Animals 搜索+剪枝
题目大意 给出一个$w\times h$的网格,定义一个连通块为一个元素个数为$n$的方格的集合$A,\forall x\in A, \exists y\in A$,使得$x,y$有一条公共边.现要求 ...
- 【例题 7-14 UVA-1602】Lattice Animals
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 借鉴网上的题解的. 思路是. 用"标准化"的思想. 确定基准点(0,0) 然后假设(0,0)是第一个连通块. 然 ...
- 网格动物UVA1602
题目大意 输入n,w,h(1<=n<=10,1<=w,h<=n).求能放在w*h网格里的不同的n连块的个数(平移,旋转,翻转算一种) 首先,方法上有两个,一是打表,dfs构造连 ...
- UVa 1602 网格动物(回溯)
https://vjudge.net/problem/UVA-1602 题意:计算n连通块不同形态的个数. 思路: 实在是不知道该怎么做好,感觉判重实在是太麻烦了. 判重就是判断所有格子位置是否都相同 ...
随机推荐
- Windows挂钩注入DLL
注入DLL实现源码:HINSTANCE g_hInstDll = NULL; HHOOK g_hHook = NULL; DWORD g_dwThreadId = 0; #ifdef _MANAGED ...
- junit断言总结
我们平时编写自己的测试类,如果没有断言,那么就没写测试的必要了. JUnit框架用一组assert方法封装了最常见的测试任务.这些assert方法可以极大地简化单元测试的编写. Assert类包含了一 ...
- org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcessor
这几天来公司,公司的SVN坏掉了,然后项目还比较大,是一个分布式的,然后同事就把项目发我了.我在myeclipse里面导入项目了,把相应的jar包也建了个人的library导入了项目,现在项目不报错了 ...
- 前端自动化测试神器-Katalon的基础用法
前言 最近由于在工作中需要通过Web端的功能进行一次大批量的操作,数据量大概在5000左右,如果手动处理, 完成一条数据的操作用时在20秒左右的话,大概需要4-5个人/天的工作量(假设一天8小时的工作 ...
- Tomcat xxx unbound
从别的地方import的代码 .出现apache unbound 第一步:选中项目右键Build Path->Configure Build Path-->选中Tomcat 7.0 unb ...
- 浏览器解析js的顺序
浏览器在读取HTML文件的时候,只有当遇到
- JavaScript 数值Number类型详解
Number 问题 如果下面的问题你都能回答对了吗? 0.1 + 0.2 == 0.3 成立吗? .e-5 表示多少? 怎么表示8进制? 怎么转换进制? 如何将字符串转换成数值或整数?反过来呢?十六进 ...
- [squid] kid1| ERROR: No forward-proxy ports configured.
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- Python学习一:基础语法
---恢复内容开始--- 本博客主要记录学习Python的过程(按照金角大王老师课程学习),整理所学知识,扎实基础.如有错误,望批评指正. 1.Python所擅长的领域 Python是一门解释型语言, ...
- DG环境的日常巡检
DG环境的日常巡检 目录 1.DG环境的日常巡检4 1.1.主库环境检查4 1.1.1.主库实例启动状态检查4 1.1.2.主库启动模式检查4 1.1.3.主库DG环境的保护模式检查4 1.1.4.主 ...