zoukankan      html  css  js  c++  java
  • 三角形面积

    三角形面积

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
     
    描述
    给你三个点,表示一个三角形的三个顶点,现你的任务是求出该三角形的面积
     
    输入
    每行是一组测试数据,有6个整数x1,y1,x2,y2,x3,y3分别表示三个点的横纵坐标。(坐标值都在0到10000之间)
    输入0 0 0 0 0 0表示输入结束
    测试数据不超过10000组
    输出
    输出这三个点所代表的三角形的面积,结果精确到小数点后1位(即使是整数也要输出一位小数位)
    样例输入
    0 0 1 1 1 3
    0 1 1 0 0 0
    0 0 0 0 0 0
    样例输出
    1.0
    0.5


    package acm03;
    
    import java.util.Scanner;
    
    public class Main4 {
    
    	private static Scanner sc;
    
    	public static void main(String[] args) {
    		sc = new Scanner(System.in);
    		while (true) {
    			int x1 = sc.nextInt();
    			int y1 = sc.nextInt();
    			int x2 = sc.nextInt();
    			int y2 = sc.nextInt();
    			int x3 = sc.nextInt();
    			int y3 = sc.nextInt();
    			if (x1 == 0 && x2 == 0 && x3 == 0 && y1 == 0 && y2 == 0 && y3 == 0) {
    				break;
    			}
    			double a, b, c, p, s;
    			a = distance(x1, y1, x2, y2);
    			b = distance(x2, y2, x3, y3);
    			c = distance(x3, y3, x1, y1);
    			p = 0.5 * (a + b + c);
    			s = Math.sqrt(p * (p - a) * (p - b) * (p - c));
    			System.out.printf("%.1f
    ", s);
    		}
    	}
    
    	public static double distance(int x1, int y1, int x2, int y2) {
    		return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
    	}
    }
    

      

  • 相关阅读:
    AUTOSAR-文档阅读
    前端 html
    http协议
    python格式化输出
    IO模型
    协程函数
    伟大的GIL
    苑之歌(进程,线程)
    python之模块导入和包
    任性计算器
  • 原文地址:https://www.cnblogs.com/airycode/p/5511468.html
Copyright © 2011-2022 走看看