UVa10522 - Height to Area(海伦公式)

THE SAMS' CONTEST

Problem 3

Height to Area 

Problem

    It's an easygeometry problem. For any triangle ABC weknow that the height from A to the line BC (or it's extension) is Ha, from B tothe line AC (or it's extension) is Hb and from C to the line AB (or it'sextension) is Hc. Now you are given these three values and you have to figureout the area of the ABC.

                              

Input

    At first the input will be an integer n. Which denotes thenumber of invalid inputs after which the input will terminate. Then there willbe three real numbers Ha, Hb and Hc per line.

Output

    For each input block there should be one output line. Forvalid inputs the line contains the area of the ABCup to 3 decimal places after the decimal point and for invalid inputs there willbe a line "These are invalid inputs!". After n invalid input sets the programwill terminate.

Sample Input

1
31.573 22.352 63.448
46.300 50.868 86.683
22.005 24.72522.914
5.710 25.635 32.805
 

Sample Output

1517.456
2219.941
311.804
These are invalid inputs!

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main {
	public static final boolean DEBUG = false;
	public static final double EPS = 1e-8;
	public StreamTokenizer tokenizer;
	public BufferedReader cin;
	public PrintWriter cout;
	public double ha, hb, hc;
	public int t;
	public int cnt;
	
	public void init() 
	{
		try {
			if (DEBUG) {
				cin = new BufferedReader(new InputStreamReader(
						new FileInputStream("d:\\OJ\\uva_in.txt")));
			} else {
				cin = new BufferedReader(new InputStreamReader(System.in));
			}
			cout = new PrintWriter(new OutputStreamWriter(System.out));
			tokenizer = new StreamTokenizer(cin);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String next() 
	{
		try {
			
			tokenizer.nextToken();
			if (tokenizer.ttype == StreamTokenizer.TT_EOF) return null;
			else if (tokenizer.ttype == StreamTokenizer.TT_WORD) return tokenizer.sval; 
			else if (tokenizer.ttype == StreamTokenizer.TT_NUMBER) return String.valueOf(tokenizer.nval);
			else return null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public void inputError()
	{
		t = (int)Double.parseDouble(next());
		cnt = 0;
	}
	
	public boolean input()
	{
		ha = Double.parseDouble(next());
		hb = Double.parseDouble(next());
		hc = Double.parseDouble(next());
		
		return true;
	}	
	
	public boolean solve() 
	{
		if (Math.abs(ha) < EPS || Math.abs(hb) < EPS || Math.abs(hc) < EPS) {
			cnt++;
			cout.println("These are invalid inputs!");
			cout.flush();
			if (cnt == t) return false;
			else return true;
		}
		
		double s = (1 / ha + 1 / hb + 1 / hc) * (1 / ha + 1 / hb - 1 / hc) * (1 / ha + 1 / hc - 1 / hb) * (1 / hb + 1 / hc - 1 / ha);
		
		if (s < EPS) {
			cnt++;
			cout.println("These are invalid inputs!");
			cout.flush();
			if (cnt == t) return false;
			else return true;
		}
		
	
		cout.printf("%.3f", 1 / Math.sqrt(s));
		cout.println();
		cout.flush();
		return true;
	}

	public static void main(String[] args) {
		Main solver = new Main();
		solver.init();
		
		solver.inputError();
		while (true) {
			solver.input();
			if (!solver.solve()) break;
		}
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值