求大佬调,20分,样例过

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

SunriseLJY @ 2024-10-22 12:55:10

只过了第一个点...

记录页面

代码

#include<cstdio>
#include<cmath>
using namespace std;

struct T{
    int x, y;
}a[5];
double ans;

int main(){
    for(int i=0; i<3; i++){
        scanf("%d", &a[i].x);
        scanf("%d", &a[i].y);
    }

    ans += sqrt(pow(a[2].x - a[1].x, 2) + pow(a[2].y - a[1].y, 2));
    ans += sqrt(pow(a[3].x - a[2].x, 2) + pow(a[3].y - a[2].y, 2));
    ans += sqrt(pow(a[3].x - a[1].x, 2) + pow(a[3].y - a[1].y, 2));

    printf("%.2lf", ans);

    return 0;
}

by Lyx8058 @ 2024-10-22 13:25:28

#include<bits/stdc++.h>
using namespace std;

struct T{
    double x, y;
}a[5];
double ans=0.0;

int main(){
    for(int i=1; i<=3; i++){
        cin>>a[i].x>>a[i].y;
    }

    ans += sqrt(pow(abs(a[2].x - a[1].x), 2) + pow(abs(a[2].y - a[1].y), 2));
    ans += sqrt(pow(abs(a[3].x - a[2].x), 2) + pow(abs(a[3].y - a[2].y), 2));
    ans += sqrt(pow(abs(a[3].x - a[1].x), 2) + pow(abs(a[3].y - a[1].y), 2));

    cout<<fixed<<setprecision(2)<<ans;

    return 0;
}

1.x,y是实数 2.输入是1-3,不是0-2


by Lyx8058 @ 2024-10-22 13:25:48

@SunriseLJY


|