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;

    }

     

  • 相关阅读:
    Linux系统下mysql修改密码遇到的问题
    Description: Field ud in com.yjj.service.impl.UserServiceImpl required a bean of type 'com.yjj.dao.UserDao' that could not be found. Action: Consider defining a bean of type 'com.yjj.dao.UserDao'
    地址的三级联动(jQuery+servlet)
    人生苦短,我用Python(目录)
    数据库增量同步
    并发编程
    Python Web 之 Flask
    jQuery 选择器
    常见性能优化方法的一些总结
    常见的浏览器兼容性问题总结
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3532956.html
Copyright © 2011-2022 走看看