bysq_ @ 2024-08-20 15:06:04
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
float jishuan(int a,int b,int c,int d){//x1 x2 y1 y2
return sqrt(fabs((a-b)*(a-b)+(c-d)*(c-d)));
}
int main() {
float x1,x2,x3,y1,y2,y3;
scanf("%f %f",&x1,&y1);
scanf("%f %f",&x2,&y2);
scanf("%f %f",&x3,&y3);
printf("%.2f",jishuan(x1,x2,y1,y2)+jishuan(x2,x3,y2,y3)+jishuan(x1,x3,y1,y3));
return 0;
}
//在第五个节点的时候,我的计算机输出是486.21,但是洛谷上面返回的值是489.20
by bysq_ @ 2024-08-20 15:07:31
输入是这个 23.234 12.123 -99.99 99.99 -1 -100
by Emil_ @ 2024-08-20 15:08:04
@bysq_
开double试试
by bysq_ @ 2024-08-20 15:11:33
@Emil_ 还是不行输出一样是那个数
by hexuchen @ 2024-08-20 15:14:38
@bysq_ 函数参数传的是 int
by hexuchen @ 2024-08-20 15:15:29
@bysq_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
float jishuan(float a,float b,float c,float d){//这里要改成float
return sqrt(fabs((a-b)*(a-b)+(c-d)*(c-d)));
}
int main() {
float x1,x2,x3,y1,y2,y3;
scanf("%f %f",&x1,&y1);
scanf("%f %f",&x2,&y2);
scanf("%f %f",&x3,&y3);
printf("%.2f",jishuan(x1,x2,y1,y2)+jishuan(x2,x3,y2,y3)+jishuan(x1,x3,y1,y3));
return 0;
}
by bysq_ @ 2024-08-20 15:16:04
@hexuchen 哦哦,解决了,谢谢大佬