POJ 3792 Area of Polycubes(模拟)
2014-04-03 21:00
369 查看
POJ 3792
大意:
按顺序给你一堆正方体,如果当前输入的正方体上下左右前后都没有跟之前的正方体有连接,就输出NO,并输出当前是第几个。如多每次输入的正方体跟之前的都有连接,那么最后输出组成的几何体的表面积。
思路:一步一步模拟就行。注意:1.要判一下有重复的输入,如果有重复的输入,要输出NO,并输出第几。。2.注意下标不要向下溢出。
大意:
按顺序给你一堆正方体,如果当前输入的正方体上下左右前后都没有跟之前的正方体有连接,就输出NO,并输出当前是第几个。如多每次输入的正方体跟之前的都有连接,那么最后输出组成的几何体的表面积。
思路:一步一步模拟就行。注意:1.要判一下有重复的输入,如果有重复的输入,要输出NO,并输出第几。。2.注意下标不要向下溢出。
#include <stdio.h> #include <algorithm> #include <vector> #include <string.h> #define max(a, b) ((a)>(b)?(a):(b)) using namespace std; int T; int n; bool vis[110][110][110]; struct node { int x, y, z; } P[1010]; void Solve() { scanf("%d", &T); for(int tt = 1; tt <= T; ++tt) { memset(vis, false, sizeof(vis)); scanf("%d", &n); printf("%d ", tt); scanf("%d,%d,%d", &P[1].x, &P[1].y, &P[1].z); P[1].x++; P[1].y++; P[1].z++; vis[P[1].x][P[1].y][P[1].z] = true; bool flag = true; for(int i = 2; i <= n; ++i) { scanf("%d,%d,%d", &P[i].x, &P[i].y, &P[i].z); P[i].x++; P[i].y++; P[i].z++; if(vis[P[i].x][P[i].y][P[i].z] == true) { if(flag) { printf("NO %d\n", i); flag = false; } continue; } vis[P[i].x][P[i].y][P[i].z] = true; if(!(vis[P[i].x-1][P[i].y][P[i].z] || vis[P[i].x+1][P[i].y][P[i].z] || vis[P[i].x][P[i].y-1][P[i].z] || vis[P[i].x][P[i].y+1][P[i].z] || vis[P[i].x][P[i].y][P[i].z-1] || vis[P[i].x][P[i].y][P[i].z+1])) { if(flag) { printf("NO %d\n", i); flag = false; } } } if(flag) { int sum =n*6; for(int i = 1; i <= n; ++i) { if(vis[P[i].x-1][P[i].y][P[i].z]) { sum -= 1; } if(vis[P[i].x+1][P[i].y][P[i].z]) { sum -= 1; } if(vis[P[i].x][P[i].y-1][P[i].z]) { sum -= 1; } if(vis[P[i].x][P[i].y+1][P[i].z]) { sum -= 1; } if(vis[P[i].x][P[i].y][P[i].z-1]) { sum -= 1; } if(vis[P[i].x][P[i].y][P[i].z+1]) { sum -= 1; } } printf("%d\n", sum); } } } int main() { ///freopen("data.in", "r", stdin); ///freopen("data.out", "w", stdout); Solve(); return 0; }
相关文章推荐
- poj 3792 Area of Polycubes (简单模拟)
- Area of Polycubes poj 3792
- POJ 3792 Area of Polycubes 解题报告
- poj 3792 Area of Polycubes
- POJ 3792 Area of Polycubes(思维)
- Area of Polycubes
- liveoj 4238 - Area of Polycubes(搜索)
- POJ 3792 Area of Polycubes 已被翻译
- 南邮 OJ 1537 G ? Area of Polycubes
- POJ 1389 Area of Simple Polygons
- hdu 2762 Area of polycube
- 【POJ】1389 Area of Simple Polygons
- poj - 1389 - Area of Simple Polygons(离线化+扫描线+线段树)
- POJ-1389-Area of Simple Polygons
- poj 1389 Area of Simple Polygons
- POJ 1389 Area of Simple Polygons(多矩形重叠面积==离散化)
- 【POJ 1389】Area of Simple Polygons(线段树+扫描线)
- POJ 3895 Cycles of Lanes(dfs+模拟)
- POJ 1389 Area of Simple Polygons(面积合并,线段树+离散化)
- poj 3083 Children of the Candy Corn (广搜,模拟,简单)