8 条题解
-
6
思路:
-
先通过两点间距离公式求出所有边的长度
-
已知3边之后,利用海伦公式直接求面积
难点:
- 两点间距离公式(可以参考P1020题解)
- 海伦公式
- sqrt() 开根号
- 保留小数
#include<iostream> #include<iomanip> #include<cmath> using namespace std; int main() { double x1, y1; double x2, y2; double x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;//定义并且输入每个点的坐标 double a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));//使用距离公式求边长 double b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));//使用距离公式求边长 double c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));//使用距离公式求边长 double p = (a + b + c) * 0.5;//求解p的值 double s=sqrt(p * (p - a) * (p - b) * (p - c));//海伦公式求解面积 cout << fixed << setprecision(2) << s;//保留小数点做对应输出 }
注:海伦公式证明 假设一个普通三角形三边长分别为a、b、c,c边的高为h
-
-
3
分析: 求出三个边长后,使用前面的海伦公式即可;注意题目要求是单精度,但实际上最后结果用单精度根本无法通过测试,原因在于单精度表示的小数范围小,精确度低,导致结果不准确,因此后面要使用double。 这道题也是挺简单的
#include<iostream> using namespace std; #include<iomanip> #include<cmath> int main() { float a, b; float x, y; float c, d; cin >> a >> b >> x >> y >> c >> d; double v1 = sqrt((a - x) * (a - x) + (b - y) * (b - y)); double v2 = sqrt((a - c) * (a - c) + (b - d) * (b - d)); double v3 = sqrt((c - x) * (c - x) + (d - y) * (d - y)); double p = (v1 + v2 + v3) / 2; cout << fixed << setprecision(2) << sqrt(p * (p - v1) * (p - v2) * (p - v3)); }
但是如果你复制了上面的代码,会只给你50分,而下面的才是满分答案,我看看有没有人能发现第一个代码的错误
#include<stdio.h> #include<math.h> int main() { double x1,x2,x3,y1,y2,y3; double a,b,c; double p,S; scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3); a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)); c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)); p=(a+b+c)/2; S=sqrt(p*(p-a)*(p-b)*(p-c)); printf("%.2lf\n",S); return 0; }
先别走,既然说到了海伦公式,就不得不介绍一下了 海伦公式又译作希伦公式、海龙公式、希罗公式、海伦-秦九韶公式。它是利用三角形的三条边的边长直接求三角形面积的公式。 表达式为:S=√p(p-a)(p-b)(p-c),它的特点是形式漂亮,便于记忆。这里p=(a+b+c)/2,也就是半周长 相传这个公式最早是由古希腊数学家阿基米德得出的,而因为这个公式最早出现在海伦的著作《测地术》中,所以被称为海伦公式。中国秦九韶也得出了类似的公式,称三斜求积术。 注1:"Metrica"《度量论》手抄本中用s作为半周长,
两种写法都是可以的,但多用p作为半周长。 它的特点是形式漂亮,便于记忆。
-
2
说实话,这题挺简单的,一遍就过了
#include<bits/stdc++.h> using namespace std; //定义一个求线段长的函数 double line(double xa,double ya,double xb,double yb) { cin>>xa>>ya>>xb>>yb; return sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)); } int main() { double xa,ya,xb,yb,xc,yc; cin>>xa>>ya>>xb>>yb>>xc>>yc; double ab,ac,bc; ab=line(xa,ya,xb,yb); ac=line(xa,ya,xc,yc); bc=line(xb,yb,xc,yc); //海伦公式 double p=(ab+ac+bc)/2; double S=sqrt(p*(p-ab)*(p-bc)*(p-ac)); cout<<fixed<<setprecision(2)<<S; return 0; }
在此,致敬海伦——秦九韶公式发现者: 海伦与秦九韶
注:关于该公式在初中数学书中勾股定理部分会提到,但考试请千万别用,阅卷老师并不愿意给分
本人亲身经历
-
1
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double x1,y1,x2,y2,x3,y3,s,a,b,c,p;//建立变量 cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;//依次输入 a=sqrt(pow(x1-x2,2)+pow(y1-y2,2)); b=sqrt(pow(x1-x3,2)+pow(y1-y3,2)); c=sqrt(pow(x2-x3,2)+pow(y2-y3,2));//计算三角形三条边长 p=(a+b+c)/2; s=sqrt(p*(p-a)*(p-b)*(p-c));//海伦公式 cout << fixed << setprecision(2) << s;//精确后输出 return 0; }
-
1
救命啊!
这题虽然我最后的结果只有50
0%的正确率,但我自测时的数据都是正确的,还有点不足。思路:
1.计算出用矩形圈出的最小面积
2.多余的面积减去
3.计算输出答案
图 一下三个点用矩形组成的最小面积是
X ^
3|(3,3).
2|
1|.(0,1).(1,3.5)
0|______________>Y
0 1 2 3 4 5
X ^ 3|[TTT]S1= 2*3.5
2|[S1T]
1|[TTT]
0|______________>Y
0 1 2 3 4 5
X ^ 3|___ _
2|W V
1|V.....|
0|______________>Y
0 1 2 3 4 5
现在的阴影就是减去部分,记得除2
但是最后代码有些错误,不知道思路哪里错了,但大部分代码都能实现,正确率50%
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double x1,y1,x2,y2,x3,y3,quyu,s = 0; cin >> x1 >> y1 >> x2 >>y2>>x3>>y3; quyu = (max(max(x1,x2),x3)-min(min(x1,x2),x3))*(max(max(y1,y2),y3)-min(min(y1,y2),y3)) ; s += abs(x1 - x2) * abs(y1-y2); s += abs(x1 - x3) * abs(y1-y3); s += abs(x2 - x3) * abs(y2-y3); cout <<fixed <<setprecision(2)<<quyu -s/2; return 0; }
-
1
#include <stdio.h> #include <math.h> double x1, y11, x2, y2, x3, y3, a, b, c, p; inline double dis(double x1, double y11, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y11 - y2) * (y11 - y2)); } int main(void) { scanf("%lf %lf %lf %lf %lf %lf", &x1, &y11, &x2, &y2, &x3, &y3); a = dis(x1, y11, x2, y2); b = dis(x2, y2, x3, y3); c = dis(x3, y3, x1, y11); p = (a + b + c) / 2; printf("%.2lf\n", sqrt(p * (p - a) * (p - b) * (p - c))); return 0; }
-
0
#include <iostream> #include <cmath> //头文件 using namespace std;//命名空间 int main()//主函数 { double x1, y1, x2, y2, x3, y3;//定义变量 cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;//输入 double a = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); double b = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2)); double c = sqrt(pow(x2 - x3, 2) + pow(y2 - y3, 2)); //求出每两点之间距离 /* 公式 √(x₁ - x₂)²+(y₁ - y₂)² */ double p = (a + b + c) / 2;//求p cout << fixed << setprecision(2) << sqrt(p * (p - a) * (p - b) * (p - c));//海伦公式 return 0; }
注:不要无脑复制代码,否则
ACCompile Error -
0
``1.两点间距离公式 2 海伦公式
3sqrt() 开根号 4保留小数
#include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() { double x1,y1,x2,y2,x3,y3; cin >> x1 >> y1 >>x2 >> y2 >> x3 >> y3; double a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));//使用距离公式求边长 double b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));//使用距离公式求边长 double c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));//使用距离公式求边长 double p = (a + b + c) * 0.5;//求解p的值 double s=sqrt(p * (p - a) * (p - b) * (p - c));//海伦公式求解面积 printf("%.2f",s); return 0; }**** ``这里用printf会更简单
- 1
信息
- ID
- 100
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 3
- 标签
- 递交数
- 274
- 已通过
- 144
- 上传者