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*/
阅读全文
0 0
- UVA1602LatticeAnimal
- Python中常用的文本处理操作
- Hadoop的计算上下行流量的案例
- 一个机器学习博士的忠告
- JVM高级特性与实践(三):垃圾收集算法 与 垃圾收集器实现
- (使用通过混淆+自己第三方保留成功混淆)AndroidStudio 混淆打包
- UVA1602LatticeAnimal
- android设置启动splash图片(消除启动白屏)不使用Appcompat主题设置的方法
- Crazepony的理念
- tornado-option模块分析
- java开发微信将消息转发到多客服
- Weird Rounding
- 外观模式(facade)c++版本
- java 后台的学习步骤
- 微信用户提现不能到账,显示NO_AUTH | 产品权限验证失败,请查看您当前是否具有该产品的权限