Algorithm training balloons in a BOX (enumeration, impersonation)

Source: Internet
Author: User

Problem description you have to write a program that allows you to simulate a balloon that is placed in a box with a spherical shape.
Next is the simulated scenario. Let's say you know a box and a point set. Each point represents a position where the balloon can be placed. Place a balloon at one point, which is the ball at the point and then inflate it until it touches the edge of the box or a balloon that has been placed before. You cannot use a point outside the box or in a balloon that has been placed before. However, you can use these points in any order you like, and you don't need each point. Your goal is to place balloons in a box in a certain order, making the balloon occupy the largest part of the overall product.
All you have to do is calculate the volume in the box that is not occupied by balloons. Input format the first line contains an integer n representing the number of points in the collection (1≤N≤6). The second line contains three integers representing the (x, y, z) coordinates of one corner of the box, and the third line contains the (x, y, z) coordinates of the opposite corner. Next n rows, each row contains three integers representing the (x, y, z) coordinates of each point in the collection. The length of each dimension of the box is nonzero, and its edge is parallel to the axis. The output format is only one line, which is the smallest volume that the box is not occupied by a balloon (rounded to an integer). Sample Input 2
0 0 0
10 10 10
3 3 3
7 7 7 Sample output 774 data scale and convention the absolute value of all coordinates is less than or equal to 1000
For 20% data: n=1
For 50% data: 1≤n≤3
For 100% data: 1≤n≤6

This question mainly studies the knowledge of geometrical simulation.

In addition, we also learned the Next-permutation function in STL Library.

This function is mainly used for perfection arrangement.

Detailed explanation

#include <cstdio>#include<algorithm>#include<cmath>#include<cstring>using namespacestd;Const intMAXN =Ten;Const DoubleINF =0x7ffffff;Const DoublePI = ACOs (-1.0);structpoint{Doublex, Y, Z DoubleR;}     A[MAXN], S, e; //S and e are two pairs of points about the box, a[] is about the position of the balloon inside the boxintN;Doubleans;Doubledis (point p1, point p2) {DoubleTMP1 = (p1.x-p2.x) * (p1.x-p2.x); DoubleTMP2 = (p1.y-p2.y) * (P1.Y-p2.y); DoubleTmp3 = (p1.z-p2.z) * (P1.z-p2.z); returnsqrt (tmp1+tmp2+Tmp3);}DoubleSolveintI//the shortest distance from the sphere position to the side of the box{    DoubleT1 = min (fabs (a[i].x-e.x), Fabs (a[i].x-s.x)); Doublet2 = min (fabs (a[i].y-e.y), Fabs (A[I].Y-s.y)); DoubleT3 = min (fabs (a[i].z-e.z), Fabs (A[i].z-s.z)); DoubleR =min (t1, T2); R=min (R, T3); returnR;}DoubleAreaDoubleR//area of the request{    return 4.0*r*r*r*pi/3.0;}intMain () { while(~SCANF ("%d", &N)) {scanf ("%lf%lf%lf", &s.x, &s.y, &s.z); scanf ("%lf%lf%lf", &e.x, &e.y, &e.z); DoubleTotal = Fabs ((s.x-e.x) * (S.Y-E.Y) * (S.z-e.z)); Memset (A,0,sizeof(a));  for(inti =0; I < n; i++) scanf ("%lf%lf%lf", &a[i].x, &AMP;A[I].Y, &a[i].z); DoubleAns =0; intVIS[MAXN];  for(inti =0; I < n; i++) Vis[i]=i;  Do        {             for(inti =0; I < n; i++) A[I].R=0; DoubleTMP =0;  for(inti =0; I < n; i++) {A[VIS[I]].R=solve (vis[i]);  for(intj =0; J < N; J + +)                {                    if(i = = J | | a[vis[j]].r = =0)                        Continue; Doublett = DIS (a[vis[j]], a[vis[i])-A[VIS[J]].R; TT= Max (TT,0.0); A[VIS[I]].R=min (A[VIS[I]].R, TT); } tmp+=Area (A[VIS[I]].R); } ans=max (ans, TMP); } while(Next_permutation (Vis, vis+n));//find the full arrangement of the positions of each centerprintf"%.0f\n", Fabs (Total-ans));//about Next_permutation:http://bbs.csdn.net/topics/392058688    }    return 0;}
View Code

Algorithm training balloons in a BOX (enumeration, impersonation)

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.