2454: 【入门】【P5735】距离函数

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:61 解决:33

题目描述


给出平面坐标上不在一条直线上三个点坐标 lns="http://www.w3.org/1998/Math/MathML">(1,1),(2,2),(3,3),坐标值是实数,且绝对值不超过 100.00,求围成的三角形周长。保留两位小数。

对于平面上的两个点 lns="http://www.w3.org/1998/Math/MathML">(1,1),(2,2),则这两个点之间的距离 lns="http://www.w3.org/1998/Math/MathML">=(21)2+(21)2

输入

输入三行,第 lns="http://www.w3.org/1998/Math/MathML"> 行表示坐标 lns="http://www.w3.org/1998/Math/MathML">(,),以一个空格隔开。

输出

输出一个两位小数,表示由这三个坐标围成的三角形的周长。

样例输入 复制

0 0
0 3
4 0

样例输出 复制

12.00

提示

数据保证,坐标均为实数且绝对值不超过 lns="http://www.w3.org/1998/Math/MathML">100,小数点后最多仅有 lns="http://www.w3.org/1998/Math/MathML">3 位。


#include<cstdio>
#include<cmath> //注意:万能头不能使用全局变量名y1
using namespace std;
int main(){
    double x1,y1,x2,y2,x3,y3,ans;
    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    ans+=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
    ans+=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
    printf("%.2f",ans);
}


#include<bits/stdc++.h>
using namespace std;
double sq(double x) {
	return x*x;
}
double dist(double x1,double y1,double x2,double y2) {
	return sqrt(sq(x1-x2)+sq(y1-y2));
}
int main(){
    double x1,y1,x2,y2,x3,y3,ans;
    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
	ans=dist(x1,y1,x2,y2);
	ans+=dist(x1,y1,x3,y3);
	ans+=dist(x2,y2,x3,y3);
	printf("%.2f",ans); 
	return 0;
}