UVA 10347 Medians(已知三角形3中线长求面积)
题意:
给你一个三角形的3条中线长度,要你输出该三角形面积. 如果输入非法就输出-1.000.
分析:
该网址有详细介绍如何通过中线长求面积的方法:
http://jwilson.coe.uga.edu/emt725/Medians.Triangle/Area.Medians.Tri.html
如果已知三角形的三条中线长度为u,v,w.那么该三角形的面积可以用下面两个公式来算:
下面来证明第二个公式:
不合法的输入就是输出的3条中线长度不能构成一个三角形时的输入.
AC代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
bool ok(double u,double v,double w)
{
if(u>0&&v>0&&w>0)
{
if(u+v>w&&w>fabs(u-v) && v+w>u&&u>fabs(w-v) && u+w>v&&v>fabs(u-w) )
return true;
}
return false;
}
int main()
{
double u,v,w;
while(scanf("%lf%lf%lf",&u,&v,&w)==3)
{
if(!ok(u,v,w))
{
printf("-1.000\n");
continue;
}
double p=(u+v+w)/2;
printf("%.3lf\n",sqrt(p*(p-u)*(p-v)*(p-w))/3.0*4);
}
return 0;
}
分享到:
相关推荐
This document contains a more detailed analysis of the Select or median of medians algorithm than is contained in the text.
Analysis of Non-Local Euclidean Medians and Its Improvement
Variability of classification by the matching familiar figures test as a function of grade level medians VARIABILITY OF CLASSIFICATION BY T H E MATCHING FAMILIAR FIGURES TEST AS A FUNCTION OF GRADE...
Chapter 9: Medians and Order Statistics Lecture Notes 9-1 Solutions 9-9 Chapter 11: Hash Tables Lecture Notes 11-1 Solutions 11-16 Chapter 12: Binary Search Trees Lecture Notes 12-1 Solutions 12-12 ...
24 Medians 60 25 Matrix multiplication 62 26 The fast Fourier transform 64 Exercises 79 3 Decompositions of graphs 87 31 Why graphs? 87 32 Depth- rst search in undirected graphs 89 33 Depth- rst ...
聚类方法,matlab语言,分类,做智能学习算法研究
2.4Medians(中位数) 2.5Matrixmultiplication(矩阵乘法) 2.6ThefastFouriertransform(快速傅里叶变换) Exercises(习题) 3Decompositionsofgraphs(图的分解) 3.1Whygraphs?(图论) 3.2Depth-...
Chapter 3. Operating System Concepts Chapter 4. Computer Networking Basics Chapter 5. Database Concepts Chapter 6. Algorithms Introduction Chapter 7. Recursion and Backtracking Chapter 8. Linked Lists...
Chapter 3. Linked Lists Chapter 4. Stacks Chapter 5. Queues Chapter 6. Trees Chapter 7. Priority Queues and Heaps Chapter 8. Disjoint Sets ADT Chapter 9. Graph Algorithms Chapter 10. Sorting Chapter ...
Chapter 9: Medians and Order Statistics Lecture Notes 9-1 Solutions 9-10 Chapter 11: Hash Tables Lecture Notes 11-1 Solutions 11-16 Chapter 12: Binary Search Trees Lecture Notes 12-1 Solutions 12-15 ...
1.版本:matlab2021a,包含仿真操作...3.内容:基于Non-Local Euclidean Medians (NLEM)的图像滤波算法的MATLAB仿真。 4.注意事项:注意MATLAB左侧当前文件夹路径,必须是程序所在文件夹位置,具体可以参考视频录。
9 Medians and Order Statistics 183 9.1 Minimum and maximum 184 9.2 Selection in expected linear time 185 9.3 Selection in worst-case linear time 189 III Data Structures Introduction 197 10 Elementary ...
3.2 Using medians instead of averages 3.3 Details Chapter 4 Organizing programs and data 4.1 Organizing computations 4.2 Organizing data 4.3 Putting it all together 4.4 Partitioning the grading ...
Chapter 3 - Growth of Functions Chapter 4 - Recurrences Chapter 5 - Probabilistic Analysis and Randomized Algorithms Part II - Sorting and Order Statistics Chapter 6 - Heapsort Chapter 7 - ...
Chapter 3 - Growth of Functions Chapter 4 - Recurrences Chapter 5 - Probabilistic Analysis and Randomized Algorithms Part II - Sorting and Order Statistics Chapter 6 - Heapsort Chapter 7 - ...
但是,在比较了JUnit中的两个运行时之后,我发现Medians of Medians算法导致运行时花费的时间比最后一个元素选择要长得多。 这可能是由于使用的比较次数以及变量初始化造成的。 优化代码可能会导致运行时间更快。
Chapter 3 - Growth of Functions Chapter 4 - Recurrences Chapter 5 - Probabilistic Analysis and Randomized Algorithms Part II - Sorting and Order Statistics Chapter 6 - Heapsort Chapter 7 - ...
Chapter 3 - Growth of Functions Chapter 4 - Recurrences Chapter 5 - Probabilistic Analysis and Randomized Algorithms Part II - Sorting and Order Statistics Chapter 6 - Heapsort Chapter 7 - ...
Chapter 3 - Growth of Functions Chapter 4 - Recurrences Chapter 5 - Probabilistic Analysis and Randomized Algorithms Part II - Sorting and Order Statistics Chapter 6 - Heapsort Chapter 7 - ...