Lattice Animals UVA
来源:互联网 发布:催收数据安全管理制度 编辑:程序博客网 时间:2024/05/16 14:21
利用打表法,首先将所有的情况全部计算出来,然后直接查表就可以了。所谓的旋转翻转其实都可以转化为原来位置依次旋转90度以及先翻转得到新的状态,然后依次旋转90度就行了。具体实现见如下代码:
#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>#include<deque>using namespace std;int n, w, h;int result[11][11][11];int dx[] = {0,0,1,-1};int dy[] = {1,-1,0,0};struct node{int x, y;node(int x1 = 0, int y1 = 0){x = x1; y = y1;}bool operator< (const node& a) const{if (x != a.x) return x < a.x;return y < a.y;}};typedef set<node> polygon;set<polygon> arr[11];void Normalize(polygon& b){int minX = b.begin()->x, minY =b.begin()->y;for (polygon::iterator it = b.begin(); it != b.end(); it++){minX = min(minX, it->x);minY = min(minY, it->y);}polygon b2;for (polygon::iterator it = b.begin(); it != b.end(); it++){b2.insert(node(it->x - minX, it->y - minY));}b = b2;}void Flip(polygon& b){polygon b2;for (polygon::iterator it = b.begin(); it != b.end(); it++){b2.insert(node(it->x,-(it->y)));}Normalize(b2);b = b2;}void Rotate(polygon& b){polygon b2;for (polygon::iterator it = b.begin(); it != b.end(); it++){b2.insert(node(it->y,-(it->x)));}Normalize(b2);b = b2;}void check(int index, polygon b, node a){b.insert(a);Normalize(b);for (int i = 0; i < 4; i++){if (arr[index].find(b) != arr[index].end()) return;Rotate(b);}Flip(b);for (int i = 0; i < 4; i++){if (arr[index].find(b) != arr[index].end()) return;Rotate(b);}arr[index].insert(b);}void get_Result(){polygon first;first.insert(node(0,0));arr[1].insert(first);for (int i = 2; i <= 10; i++){for (set<polygon>::iterator it = arr[i - 1].begin(); it != arr[i - 1].end(); it++){for (polygon::iterator it2 = (*it).begin(); it2 != (*it).end(); it2++){for (int j = 0; j < 4; j++){node b(it2->x+dx[j],it2->y+dy[j]);if (it->find(b) == it->end()){check(i, *it, b);}}}}}for (int i = 1; i <= 10; i++){for (int j = 1; j <= 10; j++){for (int k = 1; k <= 10; k++){int amount = 0;for (set<polygon>::iterator it = arr[i].begin(); it != arr[i].end(); it++){int maxX=0, maxY=0;for (polygon::iterator it2 = it->begin(); it2 != it->end(); it2++){maxX = max(maxX, it2->x); maxY = max(maxY, it2->y);}if (min(maxX, maxY) < min(j, k) && max(maxX, maxY) < max(j, k)) amount++;}result[i][j][k] = amount;}}}}int main(){get_Result();while (cin >> n >> w >> h){cout << result[n][w][h]<<endl;}return 0;}
阅读全文
0 0
- UVa 1602 Lattice Animals
- UVA 1062 Lattice Animals
- Lattice Animals UVA
- uva 1602 Lattice Animals
- UVa 1602:Lattice Animals(BFS)
- Uva 1602 Lattice Animals (网格动物)
- UVa 1602 Lattice Animals 网格动物
- 1602 - Lattice Animals
- UVa1602 - Lattice Animals
- 1602 - Lattice Animals
- UVA1602 Lattice Animals 回溯+set判重
- 搜索 【uva1602】Lattice Animals (练习题7-14 网格动物)
- Animals
- uva 687 - Lattice Practices(暴力)
- uva 1549 - Lattice Point(暴力)
- [Uva1602][Poj2170][Zoj2669][Northeastern Europe 2004] Lattice Animals 【set+傻瓜搜索】
- Uva1602 Lattice Animals 【枚举打表+形状判重】【例题7-14】
- 例题7-14 网格动物(Lattice Animals, ACM/ICPC NEERC 2004, UVa1602)
- CSS实现多栏布局的几种方式
- G
- 33muduo_net库源码分析(九)
- ChokBox的全选反选以及计算数量
- 淡入淡出放大放小
- Lattice Animals UVA
- 关于Unity3D的学习平台
- Android
- 丑数
- 深入解读Quartz的原理
- 实现频道管理
- 输入框添加姓名密码
- PAT甲级1001. A+B Format (20)
- nyoj45 棋盘覆盖