Lanqiao Cup official website fill-in-the-blank question (area of triangle)

Question description

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.

It is known that the coordinates of the three vertices of the triangle in the Cartesian coordinate system are:

```txt (2.3, 2.5) (6.4, 3.1) (5.1, 7.2)

```txt Find the area of ​​the triangle.

Note that what is being submitted is a floating point number represented in decimal form. It is required to be accurate to 3 decimal places. If it is less than 3 digits, zeros must be added.

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 128M

​​​​​​​

Where, p=Perimeter/2

The distance between two points A and B :

Among them, assume A(x1,y1),B(x2,y2)

import java.util.*;

public class Main {
    public static void main(String[] args) {
        double x1=2.3,y1=2.5;
        double x2=6.4,y2=3.1;
        double x3=5.1,y3=7.2;
        double n1=liangdian(x1,y1,x2,y2);
        double n2=liangdian(x1,y1,x3,y3);
        double n3=liangdian(x2,y2,x3,y3);
        double S=(n1+n2+n3)/2;
        double ans=Math.sqrt(S*(S-n1)*(S-n2)*(S-n3));
        System.out.printf("%.3f",ans);
    }
    public static double liangdian(double x1,double y1,double x2,double y2){
      double x=Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
      return x;
    }
}

Guess you like

Origin blog.csdn.net/s44Sc21/article/details/132793777