UVA1602LatticeAnimal

来源:互联网 发布:国家基础地理数据 编辑:程序博客网 时间:2024/06/17 07:59
//UVA1602LatticeAnimals#include<cstdio>#include<cstdlib>#include<cstring>#include<set>#include<algorithm>using namespace std;struct Cell {int x, y;Cell(int x = 0, int y = 0) : 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)const int dx[] = {-1, 1, 0, 0};const int dy[] = {0, 0, 1, -1};typedef set<Cell> Polyomino;const int MAXN = 10 + 1;set<Polyomino> poly[MAXN];int ans[MAXN][MAXN][MAXN];const int INF = 1e8;inline Polyomino Normalize(const Polyomino& p) {int minx = INF, miny = INF;for(Polyomino::const_iterator c = p.begin(); c != p.end(); c++) {minx = min(minx, c->x);miny = min(miny, c->y);}Polyomino p2;for(Polyomino::const_iterator c = p.begin(); c != p.end(); c++) {p2.insert(Cell(c ->x - minx, c->y - miny));}return p2;}inline Polyomino Rotate(const Polyomino p) {Polyomino p2;for(Polyomino::const_iterator c = p.begin(); c != p.end(); c++) {p2.insert(Cell(c->y, -c->x));}return Normalize(p2);}inline Polyomino Flip(const Polyomino p) {Polyomino p2;for(Polyomino::const_iterator c = p.begin(); c != p.end(); c++) {p2.insert(Cell(c->x, -c->y));}return Normalize(p2);}void Check_polyomino(const Polyomino p0, const Cell c) {//printf("**\n");Polyomino p = p0;p.insert(c);p = Normalize(p);int n = p.size();for(int i = 0; i < 4; i++) {if(poly[n].count(p)) return ;p = Rotate(p);}p = Flip(p);for(int i = 0; i < 4; i++) {if(poly[n].count(p)) return ;p = Rotate(p);}poly[n].insert(p);}void Generate() {Polyomino s;s.insert(Cell(0, 0));poly[1].insert(s);//for(int n = 2; n <= 10; n++) for(set<Polyomino>::iterator p = poly[n - 1].begin() ; p != poly[n - 1].end(); p++) for(Polyomino::const_iterator c = (*p).begin(); c != (*p).end(); c++){    for(int dir = 0; dir < 4; dir++) {//    if(i == 2) printf("**********************************************\n");    Cell newc(c->x + dx[dir], c->y + dy[dir]);//printf("***j = %d, i = %d, size = %d\n", j, i, poly[i].size());if(p->count(newc) == 0) Check_polyomino(*p, newc); }}for(int n = 1; n <= 10; n++) for(int w = 1; w <= 10; w++) {for(int h = 1; h <= 10; h++) {         int cnt = 0;     for(set<Polyomino>::iterator p = poly[n].begin(); p != poly[n].end(); p++) {        int maxx = 0, maxy = 0;        for(Polyomino::const_iterator c = (*p).begin(); c != (*p).end(); c++) {        maxx = max(maxx, c->x);        maxy = max(maxy, c->y);    }        if(min(maxx, maxy) < min(w, h) && max(maxx, maxy) < max(w, h)) cnt++;          }        ans[n][w][h] = cnt;     }} }int main() {Generate();int n, w, h;/*for(int i = 1; i <= 10; i++) {for(int j = 1; j <= 10; j++) {for(int k = 1; k <= 10; k++) {printf("%d ", ans[i][j][k]);}printf("//");}printf("\n");}*/while(scanf("%d%d%d", &n, &w, &h) == 3 && n) printf("%d\n", ans[n][w][h]);return 0;} /*5 1 45 2 45 3 45 5 58 3 3*/