UVa10522 - Height to Area(海伦公式)
2014-07-26 18:42
323 查看
THE SAMS' CONTEST
Problem 3Height 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.
![](http://uva.onlinejudge.org/external/105/p10522.jpg)
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 setsthe programwill terminate.
Sample Input
131.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.4562219.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; } } }
相关文章推荐
- UVA 10522 Height to Area(已知三角形三高求面积)
- uva 10522 - Height to Area(几何)
- UVa 10522 - Height to Area
- UVA 10522 Height to Area(三角形已知高求面积)
- UVA 10522 - Height to Area(计算几何)
- UVA 10522 Height to Area
- UVa 10522 - Height to Area
- UVa 10522 - Height to Area
- PercentRelativeLayout, how to set the height programatically
- jquery extension - auto height text area
- Algorithm to find the area of a polygon
- I now begin to enter Window associated development area
- A cheap way to hit test unregular area
- #177 Convert Sorted Array to Binary Search Tree With Minimal Height
- How to avoid StepInto unnecessary code area?
- 如何保持左右两个DIV高度相同( how to keep two div with same height)
- Alternative access to keyboard height
- #431 – 绑定控件的宽度到高度(Binding a Control’s Width to Its Height)
- 310. Minimum Height Trees Add to List
- How to get height of hidden element?