• NYOJ 67 三角形面积(线代,数学)


    三角形面积

    时间限制: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

     1 #include<iostream>
     2 #include<cmath>
     3 #include<iomanip>
     4 using namespace std;
     5 double get_side(int x1,int y1,int x2,int y2)
     6 {
     7     double side=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
     8     return side;
     9 }
    10 
    11 int main()
    12 {
    13     double s,a,b,c;int x1,x2,x3,y1,y2,y3;
    14     while(cin>>x1>>y1>>x2>>y2>>x3>>y3,x1||x2||x3||y1||y2||y3)
    15     {
    16         a=get_side(x1,y1,x2,y2);
    17         b=get_side(x1,y1,x3,y3);
    18         c=get_side(x2,y2,x3,y3);
    19         double p=(a+b+c)/2;
    20         s=sqrt(p*(p-a)*(p-b)*(p-c));
    21         cout<<fixed<<setprecision(1)<<s<<endl;
    22 
    23     }
    24     return 0;
    25 }
     1  
     2 #include<stdio.h>
     3 #include<math.h>
     4 int main()
     5 {
     6   int a,b,c,d,e,r,s;
     7   while(1)
     8   {
     9           scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&r);
    10           if(a==0&&b==0&&c==0&&d==0&&e==0&&r==0)   return 0;
    11    s=(a*d+b*e+c*r)-(a*r+d*e+b*c);
    12   if(s<0)   s=-s;
    13     printf("%.1f
    ",s/2.0);
    14   
    15   }return 0;
    16 }        
    
    
  • 相关阅读:
    JAVA假期第五天2020年7月10日
    JAVA假期第四天2020年7月9日
    JAVA假期第三天2020年7月8日
    JAVA假期第二天2020年7月7日
    JAVA假期第一天2020年7月6日
    CTF-sql-group by报错注入
    CTF-sql-order by盲注
    CTF-sql-sql约束注入
    CTF-sql-万能密码
    X-Forwarded-for漏洞解析
  • 原文地址:https://www.cnblogs.com/ljwTiey/p/4305565.html
Copyright © 2020-2023  润新知