UVA1602LatticeAnimal

12 篇文章 0 订阅
5 篇文章 0 订阅
//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 4
5 2 4
5 3 4
5 5 5
8 3 3
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值