POJ 3792 Area of Polycubes: Simulation

Source: Internet
Author: User
Tags bool printf

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; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.