[Solution report] balloons in a box

Source: Internet
Author: User

 

Source: http://acm.fzu.edu.cn/problem.php? PID = 1515 Fuzhou University oj15

 

There is a cube box that provides the coordinates of two vertices on the diagonal corner. in this box, there are N points, where n <= 6. put a balloon on any of the points. The balloon automatically expands until it hits the wall of the box or another balloon. The second balloon can be expanded only after a balloon expands, to maximize the total volume of a balloon, place the balloon on the N points in order. The question requires that the remaining volume be output and rounded up.

Because there are only 6 balloons in total, there are 6 in total! = 720 expansion schemes. it is easy to think of enumeration because there are few cases. use DFS to find the order of each expansion scheme, and then obtain the distance from each balloon to six sides and other balloons in sequence, and take the minimum value as the radius. one thing to note is that if a certain point does not have a balloon, it can be contained in another balloon. Obviously, the volume occupied by the balloon is 0 at this time, this problem was not taken into account at the beginning. Wa twice... code on ..

Import Java. util. arrays; <br/> Import Java. util. extends; <br/> public class main {<br/> Public static void main (string [] ARGs) {<br/> New Main (); <br/>}< br/> int total; <br/> int [] visit; <br/> int [] result; <br/> double Max; <br/> point C1, C2, PS []; <br/> int COUNT = 0; <br/> public main () {<br/> transport SC = new partition (system. in); <br/> while (SC. hasnext () {<br/> total = SC. nextint (); <br/> C1 = new point (SC. nextdouble (), SC. nextdouble (), SC. nextdouble (); // two diagonal coordinates of the box <br/> C2 = new point (SC. nextdouble (), SC. nextdouble (), SC. nextdouble (); <br/> PS = new point [total]; // coordinates of the balloon <br/> for (INT I = 0; I <total; I ++) {<br/> PS [I] = new point (SC. nextdouble (), SC. nextdouble (), SC. nextdouble (); <br/>}< br/> // enumeration balloon expansion sequence; <br/> visit = new int [total]; <br/> arrays. fill (visit, 0); <br/> result = new int [total]; <br/> max = 0; <br/> DFS (0 ); // arrange the total number in full order and put the result into the result. <br/> Double V = math. ABS (c1.x-c2.x) * (c1.y-c2.y) * (c1.z-c2.z); <br/> system. out. printf ("%. 0f ", V-max); // The minimum remaining area of the output <br/> system. out. println (); <br/>}< br/> private void DFS (INT count) {<br/> for (INT I = 0; I <total; I ++) {<br/> If (visit [I] = 0) {<br/> visit [I] = 1; <br/> result [count] = I; <br/> If (COUNT = total-1) {<br/> CAL (); // calculate the current area when the number is fully arranged to the last number <br/>} else {<br/> DFS (count + 1 ); <br/>}< br/> visit [I] = 0; <br/>}< br/> private void CAL () {<br/> double totalv = 0; // area of all circles and <br/> for (INT I = 0; I <total; I ++) {<br/> PS [I]. r = 0; <br/>}< br/> for (INT I = 0; I <total; I ++) {<br/> int now = Result [I]; <br/> // the shortest distance to the surface <br/> double X1 = math. min (math. ABS (PS [now]. x-c1.x), math. ABS (PS [now]. x-c2.x); <br/> double X2 = math. min (math. ABS (PS [now]. y-c1.y), math. ABS (PS [now]. y-c2.y); <br/> double X3 = math. min (math. ABS (PS [now]. z-c1.z), math. ABS (PS [now]. z-c2.z); <br/> PS [now]. R = math. min (x1, math. min (X2, X3); <br/> // distance to other points <br/> for (Int J = 0; j <total; j ++) {<br/> If (now = j | PS [J]. R = 0) continue; // note that other points can be included in the circle <br/> double X4 = math. SQRT (PS [now]. x-PS [J]. x) * (PS [now]. x-PS [J]. x) + (PS [now]. y-PS [J]. y) * (PS [now]. y-PS [J]. y) + (PS [now]. z-PS [J]. z) * (PS [now]. z-PS [J]. z)-PS [J]. r; <br/> // when the point is outside the circle, the radius is equal to a smaller value from the edge to the Circle <br/> PS [now]. R = math. min (PS [now]. r, X4); <br/> // if the point is inside the circle, the radius is set to 0 <br/> If (PS [now]. r <0) pS [now]. r = 0; <br/>}< br/> totalv + = 4.0d/3.0d * Math. pI * PS [now]. R * PS [now]. R * PS [now]. r; <br/>}< br/> If (totalv> MAX) max = totalv; <br/>}< br/> class point {<br/> double X, Y, Z; // coordinates <br/> double R; // radius <br/> Public point (Double X, Double Y, Double Z) {<br/> This. X = x; this. y = y; this. z = z; <br/>}< br/>} 

 

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.