80分求助!,最后一个点WA!

P5735 【深基7.例1】距离函数

_luogu_huowenshuo_ @ 2023-01-08 17:14:22

#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int a,b,c,d,e,f;
double s1,s2,s3;
int main()
{
    cin >> a >> b >> c >> d >> e >> f;
    s1 = sqrt((a-c)*(a-c)+(b-d)*(b-d));
    s2 = sqrt((a-e)*(a-e)+(b-f)*(b-f));
    s3 = sqrt((c-e)*(c-e)+(d-f)*(d-f));
    printf("%.2lf\n",s1+s2+s3);
    return 0;
}

by ud2_ @ 2023-01-08 17:27:37

实数不一定是整数。


by OIer_Kevin @ 2023-01-08 17:33:14

@huowenshuo,s1,s2,s3的值错了

AC代码:

#include<bits/stdc++.h>
#include<cmath>
using namespace std;
double a,b,c,d,e,f;
double s1,s2,s3;
int main()
{
  cin >> a >> b >> c >> d >> e >> f;
  s1 = sqrt((c-a)*(c-a)+(d-b)*(d-b));
  s2 = sqrt((e-c)*(e-c)+(f-d)*(f-d));
  s3 = sqrt((e-a)*(e-a)+(f-b)*(f-b));
  printf("%.2lf\n",s1+s2+s3);
  return 0;
}

by OIer_Kevin @ 2023-01-08 17:38:05

@huowenshuo,只改double也能过,定义变量时建议用看得懂的名字


|