实现的细节很多,学到了如何翻转、旋转、平移,get很多技巧,值得一做。
AC代码:#include#include #include #include 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 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 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 ::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 ::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)
如有不当之处欢迎指出!