Area of Polycubes
2014-04-03 19:56
253 查看
http://poj.org/problem?id=3792
题意:给出n个小正方体的中心坐标,求构成的多重小立方体的表面积。要求输入的下一个小正方体必须与之前的正方体有一个面是相交的。如果不满足条件,输出NO,并输出第几个正方体是不满足条件的。
思路:总面积s = n*6;每形成距离为1的正方体面积就减少2,如果在该正方体之前没有距离为1的正方体则该正方体不满足条件。注意重坐标。
View Code
题意:给出n个小正方体的中心坐标,求构成的多重小立方体的表面积。要求输入的下一个小正方体必须与之前的正方体有一个面是相交的。如果不满足条件,输出NO,并输出第几个正方体是不满足条件的。
思路:总面积s = n*6;每形成距离为1的正方体面积就减少2,如果在该正方体之前没有距离为1的正方体则该正方体不满足条件。注意重坐标。
#include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; const int N=1010; struct node { int x,y,z; } g ; int dis(int i,int j) { int d = abs(g[i].x-g[j].x)+abs(g[i].y-g[j].y)+abs(g[i].z-g[j].z); return d; } int main() { int t; int area = 0,o = 0; scanf("%d",&t); while(t--) { o++; int n; int flag = 0, res = 0; scanf("%d",&n); area = n*6; for (int i = 0; i < n; i++) scanf("%d,%d,%d",&g[i].x,&g[i].y,&g[i].z); for (int i = 1; i < n; i++) { flag = 0; for (int j = 0; j < i; j++) { if(dis(i,j)==1) { flag = 1; area -=2; } else if(dis(i,j)==0) { flag = 0; break; } } if (!flag) { printf("%d NO %d\n",o,i+1); break; } } if (flag) printf("%d %d\n",o,area); } return 0; }
View Code
相关文章推荐
- POJ 3792 Area of Polycubes(模拟)
- POJ 3792 Area of Polycubes 解题报告
- liveoj 4238 - Area of Polycubes(搜索)
- Area of Polycubes poj 3792
- 南邮 OJ 1537 G ? Area of Polycubes
- poj 3792 Area of Polycubes (简单模拟)
- poj 3792 Area of Polycubes
- POJ 3792 Area of Polycubes(思维)
- 思维 csu1697 Surface Area of Cubes
- hdu 2762 Area of polycube
- CSU 1697 Surface Area of Cubes (思维)
- HDU 4946 Area of Mushroom 凸包
- HDU 4946 Area of Mushroom(凸包)
- Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs
- Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes
- Codeforces Round #356 (Div. 1)-B. Bear and Tower of Cubes
- 【19.05%】【codeforces 680D】Bear and Tower of Cubes
- HDU 4946 Area of Mushroom 凸包
- HDU_4946_Area of Mushroom_凸包
- Intrusion Detection of Specific Area Based on Video