给定平面上不共线的三个整数点,求这三个点构成的三角形的面积。
输入描述:
共 行。每行两个整数 ,表示一个点的坐标。保证输入的三个点不共线。
输出描述:
共一行,一个实数,表示构成的三角形的面积,保留两位小数。
示例1
输入
0 0 0 2 1 1
输出
1.00
备注:
。
加载中...
import java.util.Scanner; public class Main { static class Point { double x, y; Point(double a, double b) { x = a; y = b; } } static class Triangle { Point a, b, c; Triangle(Point a, Point b, Point c) { this.a = a; this.b = b; this.c = c; } } static double getArea(Triangle T) { // TODO: 计算三角形T的面积 return 0.0; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int x, y; x = scanner.nextInt(); y = scanner.nextInt(); Point a = new Point(x, y); x = scanner.nextInt(); y = scanner.nextInt(); Point b = new Point(x, y); x = scanner.nextInt(); y = scanner.nextInt(); Point c = new Point(x, y); Triangle T = new Triangle(a, b, c); System.out.printf("%.2f%n", getArea(T)); scanner.close(); } }
#include
using namespace std; struct point{ double x,y; point(double A,double B){ x=A,y=B; } point() = default; }; struct triangle{ point a,b,c; triangle(point A,point B,point C){ a=A,b=B,c=C; } triangle() = default; }; double getArea(triangle T){ // TODO: 计算三角形T的面积 } int main(){ int x, y; cin >> x >> y; point a(x, y); cin >> x >> y; point b(x, y); cin >> x >> y; point c(x, y); triangle T(a, b, c); cout << fixed << setprecision(2) << getArea(T) << endl; return 0; }
import math class Point: def __init__(self, x, y): self.x = x self.y = y class Triangle: def __init__(self, a, b, c): self.a = a self.b = b self.c = c def get_area(T): # TODO: 计算三角形T的面积 pass def main(): x, y = map(int, input().split()) a = Point(x, y) x, y = map(int, input().split()) b = Point(x, y) x, y = map(int, input().split()) c = Point(x, y) T = Triangle(a, b, c) print("{:.2f}".format(get_area(T))) if __name__ == "__main__": main()
0 0 0 2 1 1
1.00