萌新#5求助啊啊啊

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

Viovegar @ 2020-09-06 10:12:33

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

double dis(double x1,double x2,double y1,double y2){
    double ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    return ans;
}

int m,n,j,k,x3,y3;
int main(){
    scanf("%d%d%d%d%d%d",&m,&n,&j,&k,&x3,&y3);
    printf("%.2f",dis(m,j,n,k)+dis(j,x3,k,y3)+dis(x3,m,y3,n));
    return 0;
}

上面代码#5是WA,给出的测试点是 23.234 12.123 -99.99 99.99 -1 -100

489.20. 于是我把

int m,n,j,k,x3,y3;

改为了double类型 于是。。。。。。 五个点全都WA掉了5555QAQ


by swl3992 @ 2020-09-06 10:14:23

@御坂mikoto 改过以后的代码?


by Viovegar @ 2020-09-06 10:16:22

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

double dis(int x1,int x2,int y1,int y2){
    double ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    return ans;
}

double m,n,j,k,x3,y3;
int main(){
    scanf("%d%d%d%d%d%d",&m,&n,&j,&k,&x3,&y3);
    printf("%.2f",dis(m,j,n,k)+dis(j,x3,k,y3)+dis(x3,m,y3,n));
    return 0;
}

by suxxsfe @ 2020-09-06 10:16:33

输出全是0我感觉你是读入的%d没改(


by Viovegar @ 2020-09-06 10:16:50

就只改了一个int


by suxxsfe @ 2020-09-06 10:17:01

看见改后代码了,还真是,改成 %lf


by Viovegar @ 2020-09-06 10:17:27

哇哦 好像是哦


by swl3992 @ 2020-09-06 10:17:54

@御坂mikoto

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

double dis(int x1,int x2,int y1,int y2){
    double ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    return ans;
}

double m,n,j,k,x3,y3;
int main(){
    //scanf("%d%d%d%d%d%d",&m,&n,&j,&k,&x3,&y3);
    scanf("%lf%lf%lf%lf%lf%lf",&m,&n,&j,&k,&x3,&y3);
  printf("%.2f",dis(m,j,n,k)+dis(j,x3,k,y3)+dis(x3,m,y3,n));
    return 0;
}

by Viovegar @ 2020-09-06 10:18:05

谢谢 感激不尽


by Viovegar @ 2020-09-06 10:20:15

。。。。。但是 他又WA了


by Viovegar @ 2020-09-06 10:22:59

@suxxsfe @swl3992 还是不对呢


| 下一页