2 solutions

  • 2
    @ 2023-10-22 15:05:16
    #include <stdio.h>
    #include <math.h>
    int main()
    {//用float设x,结果会有零点几的误差
    	double x1,x2,x3,y1,y2,y3,a=0,b=0,c=0,sum=0,i=0;
    	scanf("%lf %lf %lf %lf %lf %lf",
    	&x1,&y1,&x2,&y2,&x3,&y3);
    	a=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
    	b=sqrt(pow(x3-x1,2)+pow(y3-y1,2));
        c=sqrt(pow(x2-x3,2)+pow(y2-y3,2));
        i=(a+b+c)/2.0;
    	sum=sqrt(i*(i-a)*(i-b)*(i-c));
    	printf("%.2f",sum);
    	return 0;
    }
    
    • @ 2024-10-2 9:43:16

      学长,为什么float 会有误差呢?

  • 0
    @ 2023-9-30 13:48:13
    #include<bits/stdc++.h>
    using namespace std;
    double a1,b1,a2,b2,a3,b3;
    double get_ans(double x1,double y1,double x2,double y2)
    {
    	double ans=sqrt((pow((x1-x2),2)+pow((y1-y2),2)));
    	return ans;
    }
    int main()
    {
    	cin>>a1>>b1>>a2>>b2>>a3>>b3;
    	double temp1=get_ans(a1,b1,a2,b2);
    	double temp2=get_ans(a1,b1,a3,b3);
    	double temp3=get_ans(a2,b2,a3,b3);
    	double halfc=(temp1+temp2+temp3)/2;
    	double ans=sqrt(halfc*(halfc-temp1)*(halfc-temp2)*(halfc-temp3));
    	printf("%.2f",ans);
    }
    
    • 1

    Information

    ID
    6726
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    8
    Tags
    (None)
    # Submissions
    512
    Accepted
    82
    Uploaded By