UVA 10522 Height to Area
2011-06-26 12:14
260 查看
一直三角形三个高,求这个三角形的面积。
我自己推的时候没耐心。。没推出来。。。百度后,发现 有公式。。。T T 。。。。贴一下。
设对应三边为a,b,c
面积S=1/2ax=1/2by=1/2cz
a=2S/x b=2S/y c=2S/z
使用求积公式:
S=√[m(m-a)(m-b)(m-c)]
其中
m=1/2(a+b+c) =S( 1/x + 1/y+1/z)
m-a=S(1/y+1/z-1/x)
m-b=S(1/x +1/z-1/y)
m-c=S(1/x + 1/y-1/z)
代入得 S=S2√[( 1/x + 1/y+1/z)(1/y+1/z-1/x)(1/x +1/z-1/y)(1/x + 1/y-1/z)]
S=1/√[( 1/x + 1/y+1/z)(1/y+1/z-1/x)(1/x +1/z-1/y)(1/x + 1/y-1/z)]
不满足题意的就是s这个下面的分子等于0或者根号里面的小于0,或者x y z为0,判断一下就好,注意控制精度我的1e-6过不去,改成1e-8就过了。
我自己推的时候没耐心。。没推出来。。。百度后,发现 有公式。。。T T 。。。。贴一下。
设对应三边为a,b,c
面积S=1/2ax=1/2by=1/2cz
a=2S/x b=2S/y c=2S/z
使用求积公式:
S=√[m(m-a)(m-b)(m-c)]
其中
m=1/2(a+b+c) =S( 1/x + 1/y+1/z)
m-a=S(1/y+1/z-1/x)
m-b=S(1/x +1/z-1/y)
m-c=S(1/x + 1/y-1/z)
代入得 S=S2√[( 1/x + 1/y+1/z)(1/y+1/z-1/x)(1/x +1/z-1/y)(1/x + 1/y-1/z)]
S=1/√[( 1/x + 1/y+1/z)(1/y+1/z-1/x)(1/x +1/z-1/y)(1/x + 1/y-1/z)]
不满足题意的就是s这个下面的分子等于0或者根号里面的小于0,或者x y z为0,判断一下就好,注意控制精度我的1e-6过不去,改成1e-8就过了。
#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <string> #include <algorithm> using namespace std; const double eps = 1e-8; bool dy(double x,double y) { return x > y + eps;} // x > y bool xy(double x,double y) { return x < y - eps;} // x < y bool dyd(double x,double y) { return x > y - eps;} // x >= y bool xyd(double x,double y) { return x < y + eps;} // x <= y bool dd(double x,double y) { return fabs( x - y ) < eps;} // x == y int main() { int ncases; double x,y,z; scanf("%d",&ncases); while( ncases ) { scanf("%lf%lf%lf",&x,&y,&z); if( dd(x,0.0) || dd(y,0.0) || dd(z,0.0) ) { printf("These are invalid inputs!/n"); ncases--; continue; } double p = (1/x + 1/y + 1/z)*(1/y + 1/z - 1/x)*(1/x + 1/z - 1/y)*(1/x + 1/y - 1/z); if( xyd(p,0.0) ) { printf("These are invalid inputs!/n"); ncases--; continue; } double area = 1/sqrt(p); printf("%.3lf/n",area); } return 0; }
相关文章推荐
- 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(三角形已知高求面积)
- UVa10522 - Height to Area(海伦公式)
- scrollTop clientTop offsetTop scrollHeight clientHeight clientWidth的区别及用法
- UVAlive 7041 The Problem to Slow Down You(回文树)
- UVa 10290 - {Sum+=i++} to Reach N
- uva_10739 - String to Palindrome (普通DP)
- I.MX6 change boot partition 1 to User area
- How to build the topology of an OSPF area
- MVC-RedirectToAction跳转到其他Area
- UVA 1541 - To Bet or Not To Bet(概率递推)
- 69.You are working on an instance started using the SPFILE. You want to move the Flash Recovery Area
- Programmatically split an editor area to show two editors side by side
- uva 10739 - String to Palindrome(带增删改操作的回文串问题)
- So you want to be a 2n-aire? UVA - 10900