UVA1602
2016-09-28 18:52
295 查看
实现的细节很多,学到了如何翻转、旋转、平移,get很多技巧,值得一做。
AC代码:
如有不当之处欢迎指出!
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 .count(p)!=0) return; p=rotate(p); } p=flip(p); for(int i=0;i<4;++i){ if(poly .count(p)!=0) return; p=rotate(p); } poly .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 .begin();p!=poly .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 [w][h]=cnt; } } int main(){ solve(); int n,w,h; while(scanf("%d%d%d",&n,&w,&h)==3){ printf("%d\n",ans [w][h]); } return 0; }
如有不当之处欢迎指出!
相关文章推荐
- UVA - 1602(Polyomino的存储和判重)
- 【例题 7-14 UVA-1602】Lattice Animals
- UVA 1602 Lattice Animals
- 例题7-14 网格动物(Lattice Animals, ACM/ICPC NEERC 2004, UVa1602)
- UVa1602 - Lattice Animals
- UVa 1602 网格动物(回溯)
- Uva1602 Lattice Animals 【枚举打表+形状判重】【例题7-14】
- uva 1602 Lattice Animals
- 例题7-14 网格动物 UVa1602
- UVa 1602 Lattice Animals 网格动物
- Lattice Animals UVA - 1602
- UVA - 1602 Lattice Animals : 完备信息 set
- uva1602 无方向位置的姿势判重
- UVA-1602 Lattice Animals 搜索问题(打表+set)
- Uva 1602 Lattice Animals (网格动物)
- UVA1602 Lattice Animals 网格动物 (暴力,STL)
- [Uva1602][Poj2170][Zoj2669][Northeastern Europe 2004] Lattice Animals 【set+傻瓜搜索】
- UVa 1602:Lattice Animals(BFS)
- UVa 1602 Lattice Animals
- 搜索 【uva1602】Lattice Animals (练习题7-14 网格动物)