HDU 5839 Special Tetrahedron (2016CCPC online race 08) (Violence + pruning)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5839

In a three-dimensional coordinate, give you n points, ask you how many tetrahedron (4 points, 6 edges) and satisfy at least four sides equal to the rest of the two nonadjacent.

The 4 cycle of violence, but in the 3rd cycle when the need to determine whether it is isosceles triangle, this is a pruning. In the 4th cycle of the time to determine whether the 4-point coplanar (cross-multiplication), 5 or 6 sides equal +1,4 sides equal to determine whether the other side of the intersection on the line.

After the game, I thought I was too much food.

1 //#pragma COMMENT (linker, "/stack:102400000, 102400000") 82#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <ctime>Ten#include <list> One#include <Set> A#include <map> - using namespacestd; -typedefLong LongLL; thetypedef pair <int,int>P; - Const intN = 2e2 +5; - intCost[n][n];//The square of the side length of two points - structEdge { +     intx, y, Z; -}a[n*N]; +  A intMain () at { -     intT; -scanf"%d", &t); -      for(intCA =1; CA <= T; ++CA) { -         intN; -scanf"%d", &n); in          for(inti =1; I <= N; ++i) { -scanf" %d%d%d", &a[i].x, &AMP;A[I].Y, &a[i].z); to              for(intj =1; J < I; ++j) { +COST[I][J] = cost[j][i] = (a[i].x-a[j].x) * (a[i].x-a[j].x) + (A[I].Y-A[J].Y) * (A[I].Y-A[J].Y) + (a[i].z-a[j].z) * (A [I].z-a[j].z); -             } the         } * edge s1, S2, S3; $         intans, res =0, x1, x2, y1, y2, len1, len2;//X1 Y1 is a triangular face with different sides of the ends len1 for the isosceles triangle of the waistPanax Notoginseng          for(intI1 =1; I1 < n; ++I1) { -              for(intI2 = I1 +1; I2 < n; ++I2) { the                  for(inti3 = I2 +1; i3 < N; ++i3) { +                     //determine if 3 points form isosceles triangle A                     if(Cost[i1][i2]! = Cost[i1][i3] && cost[i2][i3]! = Cost[i1][i2] && cost[i2][i3]! =Cost[i1][i3]) the                         Continue; +                     Else if(Cost[i1][i2] = = Cost[i1][i3] && Cost[i1][i2] = =Cost[i2][i3]) { -Len1 = Cost[i1][i2], x1 = y1 =0; $                     } $                     Else if(Cost[i1][i2] = =Cost[i2][i3]) { -Len1 = Cost[i1][i2], x1 = i1, y1 =i3; -                     } the                     Else if(Cost[i1][i2] = =Cost[i1][i3]) { -Len1 = Cost[i1][i2], x1 = i2, y1 =i3;Wuyi                     } the                     Else { -Len1 = Cost[i2][i3], x1 = i1, y1 =I2; Wu                     } -                      for(intI4 = i3 +1; I4 <= N; ++I4) { About                         if(COST[I1][I4]! = Cost[i2][i4] && cost[i1][i4]! = Cost[i3][i4] && cost[i3][i4]! =Cost[i2][i4]) $                             Continue; -                         Else if(Cost[i1][i4] = = Cost[i2][i4] && Cost[i1][i4] = =Cost[i3][i4]) { -Len2 = Cost[i1][i4], x2 = y2 =0; -                         } A                         Else if(Cost[i1][i4] = =Cost[i2][i4]) { +Len2 = Cost[i1][i4], x2 = i3, y2 =I4; the                         } -                         Else if(Cost[i1][i4] = =Cost[i3][i4]) { $Len2 = Cost[i1][i4], x2 = i2, y2 =I4; the                         } the                         Else { theLen2 = Cost[i2][i4], x2 = i1, y2 =I4; the                         } -s1.x=a[i2].x-a[i1].x;s1.y=a[i2].y-a[i1].y;s1.z=a[i2].z-a[i1].z;  ins2.x=a[i3].x-a[i1].x;s2.y=a[i3].y-a[i1].y;s2.z=a[i3].z-a[i1].z;  thes3.x=a[i4].x-a[i1].x;s3.y=a[i4].y-a[i1].y;s3.z=a[i4].z-a[i1].z;  theans=s1.x*s2.y*s3.z+s1.y*s2.z*s3.x+s1.z*s2.x*s3.y-s1.z*s2.y*s3.x-s1.x*s2.z*s3.y-s1.y*s2.x*s3.z;  About                         if(ans = =0)//whether 4 points are coplanar the                             Continue; the                         if(!x1 | |!x2) {//6 sides or 5 sides equal the                             if(Len1 = =len2) +res++; -                         } the                         Else {Bayi                             if(Len1 = = Len2 && (x1! = x2 && X1! = y2 && y1! = x2 && y1! = y2))//Four edges equal theres++; the                         } -                     } -                 } the             } the         } theprintf"Case #%d:%d\n", CA, res); the     } -     return 0; the}
View Code

HDU 5839 Special Tetrahedron (2016CCPC online race 08) (Violence + pruning)

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.