poj 3792 Area of Polycubes

http://poj.org/problem?id=3792

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <cmath>

 4 #include <algorithm>

 5 #define maxn 2000

 6 using namespace std;

 7 struct node

 8 {

 9     int x,y,z;

10 }p[maxn];

11 int main()

12 {

13     int t,n;

14     scanf("%d",&t);

15     for(int i=1; i<=t; i++)

16     {

17          int ans=0;

18         scanf("%d",&n);

19         scanf("%d,%d,%d%*c",&p[0].x,&p[0].y,&p[0].z);

20         ans+=6;

21         bool flag=true;

22         for(int j=1; j<n; j++)

23         {

24             scanf("%d,%d,%d%*c",&p[j].x,&p[j].y,&p[j].z);

25             if(!flag)

26             {

27                 continue;

28             }

29             int k=0;

30             ans+=6;

31             flag=false;

32             while(k<j)

33             {

34                 int d=(abs(p[k].x-p[j].x)+abs(p[k].y-p[j].y)+abs(p[k].z-p[j].z));

35                 if(d==0)

36                 {

37                    break;

38                 }

39                 if(d==1)

40                 {

41                     flag=true;

42                     ans-=2;

43                 }

44                 k++;

45             }

46             if(!flag||k!=j)

47             {

48                 printf("%d NO %d\n",i,j+1);

49             }

50         }

51         if(flag)

52         {

53             printf("%d %d\n",i,ans);

54         }

55     }

56     return 0;

57 }
View Code

 

你可能感兴趣的:(cube)