NOIP信息学1034:计算三角形面积

时间限制: 1000 ms 内存限制: 65536 KB
提交数: 28010 通过数: 8289
【题目描述】
平面上有一个三角形,它的三个顶点坐标分别为(x1, y1), (x2, y2), (x3, y3),那么请问这个三角形的面积是多少,精确到小数点后两位。

【输入】
输入仅一行,包括6个单精度浮点数,分别对应x1, y1, x2, y2, x3, y3。

【输出】
输出也是一行,输出三角形的面积,精确到小数点后两位。

【输入样例】
0 0 4 0 0 3
【输出样例】
6.00
【来源】

No

代码如下:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double x1,x2,x3,y1,y2,y3,p,s,a,b,c;
cout.precision(2);
cin>>x1>>y1>>x2>>y2>>x3>>y3;
a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)); 
c=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
cout<<fixed<<s; 
return 0;
}

  

https://pan.baidu.com/s/1fAuVscWNdApIGmKZK4Wb6Q 
提取码:u56x

猜你喜欢

转载自www.cnblogs.com/yyjy-edu/p/12652633.html