首页 > 专题系列 > Java解POJ > POJ 2208 Pyramids [解题报告] Java
2013
11-10

POJ 2208 Pyramids [解题报告] Java

Pyramids

问题描述 :

Recently in Farland, a country in Asia, a famous scientist Mr. Log Archeo has discovered ancient pyramids. But unlike those in Egypt and Central America, they have triangular (not rectangular) foundation. That is, they are tetrahedrons in mathematical sense. In order to find out some important facts about the early society of the country (it is widely believed that the pyramid sizes are in tight connection with Farland ancient calendar), Mr. Archeo needs to know the volume of the pyramids. Unluckily, he has reliable data about their edge lengths only. Please, help him!

输入:

The file contains six positive integer numbers not exceeding 1000 separated by spaces, each number is one of the edge lengths of the pyramid ABCD. The order of the edges is the following: AB, AC, AD, BC, BD, CD.

输出:

A real number — the volume printed accurate to four digits after decimal point.

样例输入:

1000 1000 1000 3 4 5

样例输出:

1999.9938

解题代码:

//* @author:
import java.util.*;

public class Main {
 static double area( double l1, double l2, double l3 )
{
	double p = ( l1 + l2 + l3 ) / 2;
	return Math.sqrt( p * (p-l1) * (p-l2) * (p-l3) );
}

static double sq( double a )
{
	return a * a;
}

static public void main( String [] str ) throws Exception{
       Scanner sc = new Scanner(System.in);
 	double ab,ad,ac,bc,bd,cd,ah,dh,af,sabc,sbcd, hi, v, bh1, bh2;
       ab=sc.nextDouble();
       ac=sc.nextDouble();
       ad=sc.nextDouble();
       bc=sc.nextDouble();
       bd=sc.nextDouble();
       cd=sc.nextDouble();

	
	sabc = area( ab, bc, ac );
	sbcd = area( bc, cd, bd );
	
	ah = sabc * 2 / bc;
	dh = sbcd * 2 / bc;


	bh1 = Math.sqrt( bd*bd - dh*dh );
	if( cd*cd > bd*bd + bc*bc ) bh1 = -bh1;

	bh2 = Math.sqrt( ab*ab - ah*ah );
	if( ac*ac > ab*ab + bc*bc ) bh2 = -bh2;
	
	af = Math.sqrt( ad*ad - sq( bh1 - bh2 ) );
	hi = area( af, dh, ah ) * 2 / ah;
	v = sabc * hi / 3;

	System.out.printf( "%.4f\n", v );

  }
}

  1. Gucci New Fall Arrivals

    This is really nice to know. I hope it will be successful in the future. Good job on this and keep up the good work.

  2. 约瑟夫也用说这么长……很成熟的一个问题了,分治的方法解起来o(n)就可以了,有兴趣可以看看具体数学的第一章,关于约瑟夫问题推导出了一系列的结论,很漂亮