import java.io.*; import java.util.*; import java.awt.geom.*; /** * Solution to 3D Printer. * * @author vanb */ public class threedprinter_vanb { public Scanner sc; public PrintStream ps; /** * A 3D Point. * * @author vanb */ public class Point3D { public double x, y, z; /** * Distance from this point to another point. * * @param p Another point * @return Distance from here to p */ public double distanceTo( Point3D p ) { double dx = p.x-x; double dy = p.y-y; double dz = p.z-z; return Math.sqrt( dx*dx + dy*dy + dz*dz ); } } /** This is the number of vertices of a polygon */ public int v; /** These points form a polygon */ public Point3D points[]; /** * Read a polygon from the input, and allocate all of the structures. */ public void readpoly() { v = sc.nextInt(); points = new Point3D[v]; for( int i=0; i0.0001 ) System.err.println( "PANIC! Polygon isn't in a plane!" ); } // OK, now that we know the equation of the plane (ax+by+cz+d=0), // we can find the distance of the top, and thus the height of the pyramid. double height = Math.abs((a*top.x+b*top.y+c*top.z+d)/(Math.sqrt( a*a+b*b+c*c ))); // Add in the volume of the pyramid. volume += height * basearea / 3.0; } } // Judges' stuff, to make sure roundoff error isn't a problem. String answer = String.format( "%.4f", volume ); if( answer.endsWith( "50" ) || answer.endsWith( "49" ) ) { System.err.println( answer + " is too close to a cusp"); } System.out.println( answer ); // Print the answer! ps.printf( "%.2f", volume ); ps.println(); } } /** * @param args */ public static void main( String[] args ) throws Exception { new threedprinter_vanb().doit(); } }