POJ 3792:http://poj.org/problem?id=3792
Effect:
In order to give you a bunch of cubes, if the current input of the cube before and after the upper and lower sides are not connected with the previous cube, output no, and output is currently the first few. If each input cube is connected to the previous one, then the surface area of the geometry is finally output.
Train of thought: Step by step simulation on the line. Note: 1. To give a duplicate of the input, if there are duplicate input, to output no, and output the first few. 2. Note that the subscript does not overflow downward.
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
#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) {print
F ("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; }