AOJ0073 Surface Area of Quadrangular Pyramid

問題リンク Surface Area of Quadrangular Pyramid

  • 解法

底面の面積はx*xです。
側面の2等辺三角形の1つの面積sは
s = x * sqrt(x*x+h*h) / 2
です。
よって四角すいの表面積Sは
S = x*x + s*4 = x*x + 2*x*sqrt(x*x+h*h)
で求まります

  • ソース
import java.util.Scanner;

//Surface Area of Quadrangular Pyramid
public class AOJ0073 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			double x = sc.nextDouble();
			double h = sc.nextDouble();
			if(x==0&&h==0)break;
			double r = Math.sqrt(h*h+(x/2)*(x/2));
			System.out.println((x*x+2*r*x));
		}
	}
}