zoukankan      html  css  js  c++  java
  • 一月24日新生冬季练习赛解题报告D.三角形面积

    水的离谱:

    啊啊啊啊啊啊

    已知三边求面积可以:

    #include<iostream>

    #include<string.h>

    #include<stdio.h>

    #include<queue>

    #include<stack>

    #include<map>

    #include<vector>

    #include<cmath>

    #include<iomanip>

    using namespace std;

     

    struct point

    {

        double x;

        double y;

    }poin[101];

     

    int main()

    {

        int t;

        cin>>t;

        while(t--)

        {

            cin>>poin[0].x>>poin[0].y>>poin[1].x>>poin[1].y>>poin[2].x>>poin[2].y;

            double a=sqrt(pow((poin[0].x-poin[1].x)*1.0,2.0)+(pow((poin[0].y-poin[1].y)*1.0,2.0)));

            double b=sqrt(pow((poin[0].x-poin[2].x)*1.0,2.0)+(pow((poin[0].y-poin[2].y)*1.0,2.0)));

            double c=sqrt(pow((poin[2].x-poin[1].x)*1.0,2.0)+(pow((poin[2].y-poin[1].y)*1.0,2.0)));

        if(a+b>c&&a+c>b&&b+c>a)

            {

                double d=0.5*(a+b+c);

                double s=sqrt(d*(d-a)*(d-b)*(d-c));

                cout<<setprecision(2)<<std::fixed<<s<<endl;

            }

            else

                cout<<"fail"<<endl;

          }

          return 0;

    }

     

    茶几也可以:

    #include<iostream>

    #include<string.h>

    #include<stdio.h>

    #include<queue>

    #include<stack>

    #include<map>

    #include<vector>

    #include<cmath>

    #include<iomanip>

    using namespace std;

     

    #define minn 1e-8

     

    struct point

    {

        double x;

        double y;

    }poin[101];

     

    double cross(point p1,point p0,point p2)

    {

        return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p1.y);

    }

     

    int main()

    {

        int t;

        cin>>t;

        while(t--)

        {

            cin>>poin[0].x>>poin[0].y>>poin[1].x>>poin[1].y>>poin[2].x>>poin[2].y;

            double ans=cross(poin[1],poin[0],poin[2]);

            if(ans<=minn&&ans+minn>=0)

                 cout<<"no"<<endl;

            else

               cout<<ans/2<<endl;

        }

        return 0;

    }

     

  • 相关阅读:
    H3C无线配置2三层注册典型配置举例(集中转发)
    PHP 中 exec() 执行系统外部命令
    salesforce 从零开始(一)开始使用
    求和平均统计
    VS2012 如何进行远程调试
    H5跳转小程序的方法
    C#提取HTML中IMG标签的URL
    数据库链接字符串中的细节(integrated security=true;MultipleActiveResultSets=true)
    运行cmd状态下MySQL导入导出.sql文件
    sql server 2008 rownumber 分页sql语句
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3532956.html
Copyright © 2011-2022 走看看