17 条题解

  • 9
    @ 2023-6-2 10:00:30

    解析

    1. 先通过两点间距离公式求出所有边的长度

      image

    2. 已知3边之后,利用海伦公式直接求面积

      image

    难点

    1. 两点间距离公式(可以参考P0008题解)
    2. 海伦公式
    3. sqrt() 开根号
    4. 保留小数

    题解

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <cstdio>
    using namespace std;
    int main()
    {
        double x1, y1;
        double x2, y2;
        double x3, y3;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;                        // 定义并且输入每个点的坐标
        double a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); // 使用距离公式求边长
        double b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)); // 使用距离公式求边长
        double c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)); // 使用距离公式求边长
        double p = (a + b + c) * 0.5;                                   // 求解p的值
        double s = sqrt(p * (p - a) * (p - b) * (p - c));               // 海伦公式求解面积
        printf("%.2lf", s);                                             // 保留小数点做对应输出
    }
    

    注:海伦公式证明 假设一个普通三角形三边长分别为a、b、c,c边的高为h image image image

    • @ 2024-4-5 21:35:37

      海伦公式证明的第一步的b方-h方和a方-h方是不是都忘了加根号

  • 2
    @ 2023-6-4 11:11:16

    计算都写在输出里了,有亿点点长,请谅解。

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    double xa,ya,xb,yb,xc,yc;
    scanf ("%lf %lf %lf %lf %lf %lf",&xa,&ya,&xb,&yb,&xc,&yc);
    printf ("%.2lf",sqrt((sqrt(pow(abs(xa - xb),2) + pow(abs(ya - yb),2)) + sqrt(pow(abs(xa - xc),2) + pow(abs(ya - yc),2)) + sqrt(pow(abs(xb - xc),2) + pow(abs(yb - yc),2))) / 2.0 * ((sqrt(pow(abs(xa - xb),2) + pow(abs(ya - yb),2)) + sqrt(pow(abs(xa - xc),2) + pow(abs(ya - yc),2)) + sqrt(pow(abs(xb - xc),2) + pow(abs(yb - yc),2))) / 2.0 - sqrt(pow(abs(xa - xb),2) + pow(abs(ya - yb),2))) * ((sqrt(pow(abs(xa - xb),2) + pow(abs(ya - yb),2)) + sqrt(pow(abs(xa - xc),2) + pow(abs(ya - yc),2)) + sqrt(pow(abs(xb - xc),2) + pow(abs(yb - yc),2))) / 2.0 - sqrt(pow(abs(xa - xc),2) + pow(abs(ya - yc),2))) * ((sqrt(pow(abs(xa - xb),2) + pow(abs(ya - yb),2)) + sqrt(pow(abs(xa - xc),2) + pow(abs(ya - yc),2)) + sqrt(pow(abs(xb - xc),2) + pow(abs(yb - yc),2))) / 2.0 - sqrt(pow(abs(xb - xc),2) + pow(abs(yb - yc),2)))));
    return 0;
    
    }
    
    
    
  • 1
    @ 2023-6-3 23:10:14

    题解:

    #include <iostream>
    #include <cmath>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
        double x1,x2,x3,y1,y2,y3;
        double a,b,c,p,s;
        cin>> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        a=sqrt(pow(abs(x1-x2), 2) + pow(abs(y1-y2), 2));
        b=sqrt(pow(abs(x2-x3), 2) + pow(abs(y2-y3), 2));
        c=sqrt(pow(abs(x1-x3), 2) + pow(abs(y1-y3), 2));
        p=(a+b+c)/2;
        s=sqrt(p*(p-a)*(p-b)*(p-c));
        cout<< fixed << setprecision(2) << s <<endl;
    }
    
    • 1
      @ 2023-6-3 18:15:01
      #include <iostream>
      #include <cmath>
      #include <iomanip>
      using namespace std;
      int main()
      {
          double x1,y1,x2,y2,x3,y3;
          cin>>x1>>y1>>x2>>y2>>x3>>y3;
          double a=sqrt(abs(x2-x1)*abs(x2-x1)+abs(y2-y1)*abs(y2-y1));//注意用绝对值
          double b=sqrt(abs(x3-x1)*abs(x3-x1)+abs(y3-y1)*abs(y3-y1));
          double c=sqrt(abs(x2-x3)*abs(x2-x3)+abs(y2-y3)*abs(y2-y3));
          double p=(a+b+c)/2;
          double s=sqrt(p*(p-a)*(p-b)*(p-c));
          cout<<fixed<<setprecision(2)<<s;
          return 0;
      }
      
      • 1
        @ 2023-6-3 17:40:44
        #include <iostream>
        #include <iomanip>
        #include <cmath>
        using namespace std;
        int main()
        {
            double x1, y1, x2, y2, x3, y3;
            cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
            double a = sqrt(pow(abs(x1-x2), 2) + pow(abs(y1-y2), 2));
            double b = sqrt(pow(abs(x1-x3), 2) + pow(abs(y1-y3), 2));
            double c = sqrt(pow(abs(x2-x3), 2) + pow(abs(y2-y3), 2));
            double p = (a + b + c) / 2;
            double s = sqrt(p * (p - a) * (p - b) * (p - c));
            cout << fixed << setprecision(2) << s;
            return 0;
        }
        
        • 1
          @ 2023-6-2 22:19:33

          解析 1.通过两点间距离公式求所有边的长 image

          2.利用海伦公式求面积(题中有公式) image

          题解

          1.导入头文件、命名空间

          • 根据个人习惯选择,我使用的以下两个仅供参考
          #include <cstdio>
          #include <cmath>
          

          2.主函数 略

          3.输入

          double x1,y1,x2,y2,x3,y3;
          scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
          

          也可以使用cin,但头文件要引入#include <iostream>

          4.数据处理

          • 计算三边长(d12,d23,d13三个变量表示三边长)
          d12 =  sqrt(pow((x1-x2),2) + pow((y1-y2),2));
          d13 =  sqrt(pow((x1-x3),2) + pow((y1-y3),2));
          d23 =  sqrt(pow((x2-x3),2) + pow((y2-y3),2));
          
          • 求p值 double p = (d12 + d13 + d23)/2.0;
          • 海伦公式算面积(s)
          s = sqrt(p*(p-d12)*(p-d13)*(p-d23));
          

          5.输出

          printf("%.2lf",s);
          

          当然还可以用cout<<fixed << setprecision(2)<<s 但头文件要引入#include <iostream>#include <iomanip>

          • 0
            @ 2024-6-5 19:25:43

            题解 c++ #include <bits/stdc++.h> //hetao4040809 using namespace std; int main() { double x1, y1; double x2, y2; double x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); double b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)); double c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)); double p = (a + b + c) * 0.5; double s = sqrt(p * (p - a) * (p - b) * (p - c)); printf("%.2lf", s); return 0; }

            • 0
              @ 2024-5-24 17:08:43
              #include <iostream>
              #include <cmath>
              #include<cstdio>
              #include <iomanip>
              using namespace std;
              int main()
              {
                  double a,b,c,d,e,f,g,h,i,j;
                  cin >> a >> b >> c >> d >> e >> f;
                  g = sqrt(pow(abs(a - c),2) + pow(abs(b - d),2));
                  h = sqrt(pow(abs(a - e),2) + pow(abs(b - f),2));
                  i = sqrt(pow(abs(c - e),2) + pow(abs(d - f),2));
                  j = (g + h + i) / 2.0;
                  cout << fixed << setprecision(2) << sqrt(j * (j - g) * (j - h) * (j - i));
                  return 0;
              }
              
              • 0
                @ 2024-4-6 20:49:38
                
                #include <cmath>
                #include <iostream>
                #include <cstdio>
                using namespace std;
                int main()
                {
                double Xa,Ya,Xb,Yb,Xc,Yc; //坐标变量
                cin >> Xa >> Ya >> Xb >> Yb >> Xc >> Yc; //输入
                double a = sqrt((Xa - Xb) * (Xa - Xb) + (Ya - Yb) * (Ya - Yb)); // 使用距离公式求边长
                double b = sqrt((Xa - Xc) * (Xa - Xc) + (Ya - Yc) * (Ya - Yc)); // 使用距离公式求边长
                double c = sqrt((Xb - Xc) * (Xb - Xc) + (Yb - Yc) * (Yb - Yc)); // 使用距离公式求边长
                double p; //海洛公式中的p
                p = (a + b + c)/2;
                double s = sqrt(p*(p-a)*(p-b)*(p-c));
                printf("%.2lf",s);
                return 0;
                }
                
                
                • 0
                  @ 2023-9-17 8:57:12

                  (介题老司嗦地挺清粗跌,自接桑代码吼)

                  #include <bits/stdc++.h>
                  using namespace std;
                  int main()
                  {
                      double xa,ya,xb,yb,xc,yc;
                      cin>>xa>>xb>>ya>>yb>>xc>>yc;
                      //输出其他题解那里有,不会可以借(抄)鉴(袭)一下那些东西哈(题友对不起
                      return 0;
                  }
                  

                  (可以搞定了吧,那就点个赞呗)

                  • 0
                    @ 2023-7-19 19:21:43

                    计算三角形面积

                    思路:

                    通过两点算出距离→代入海伦公式→保留2位并输出

                    上代码:

                    相信大家都看得懂,就说一下核心代码啊

                    两点算距离公式

                    double f(double xa,double ya,double xb,double yb)
                    {
                        double a = abs(xa - xb);
                        double b = abs(ya - yb);
                        double n = sqrt(pow(a,2) + pow(b,2));
                        return n;
                    }
                    

                    海伦公式

                    double p=(n1+n2+n3)/2;
                    double s=sqrt(p*(p-n1)*(p-n2)*(p-n3));
                    
                    • 0
                      @ 2023-7-5 22:27:36

                      解析

                      1. 先通过两点间距离公式求出所有边的长度 image
                      2. 已知3边之后,利用海伦公式直接求面积 image

                      难点​:

                      1. 两点间距离公式(可以参考P0008题解)
                      2. 海伦公式
                      3. sqrt() 开根号
                      4. 保留小数
                      #include <iostream>
                      #include <cstdio>
                      #include <cmath>
                      using namespace std;
                      int main()
                      {
                          double  x1,y1,x2,y2,x3,y3;                          //定义3个点的坐标
                          double a,b,c,S,p;
                          cin >>x1>>y1>>x2>>y2>>x3>>y3;       //输入3个点的坐标
                          a = sqrt(pow((x2-x1),2)+pow((y2-y1),2)); //用两点间距离公式计算边长a
                          b = sqrt(pow((x3-x2),2)+pow((y3-y2),2));//用两点间距离公式计算边长b
                          c = sqrt(pow((x1-x3),2)+pow((y1-y3),2));//用两点间距离公式计算边长c
                          p = (a+b+c)/2;
                          S = sqrt(p*(p-a)*(p-b)*(p-c));
                          printf("%.2f",S);
                          return 0;
                      }
                      
                      • 0
                        @ 2023-6-6 21:13:13

                        #include<bits/stdc++.h> using namespace std; int main() { double x1,y1,x2,y2,x3,y3,s,a,b,c,p; cin>>x1>>y1>>x2>>y2>>x3>>y3; a=sqrt(pow(abs(x1-x2), 2) + pow(abs(y1-y2), 2)); b=sqrt(pow(abs(x2-x3), 2) + pow(abs(y2-y3), 2)); c=sqrt(pow(abs(x1-x3), 2) + pow(abs(y1-y3), 2)); p=(a+b+c)/2; s=sqrt(p*(p-a)(p-b)(p-c)); cout<<fixed<<setprecision(2)<<s; return 0; }

                        • 0
                          @ 2023-6-4 19:24:16

                          #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double a = sqrt(pow(abs(x1-x2), 2) + pow(abs(y1-y2), 2)); double b = sqrt(pow(abs(x1-x3), 2) + pow(abs(y1-y3), 2)); double c = sqrt(pow(abs(x2-x3), 2) + pow(abs(y2-y3), 2)); double p = (a + b + c) / 2; double s = sqrt(p * (p - a) * (p - b) * (p - c)); cout << fixed << setprecision(2) << s; return 0; }

                          • 0
                            @ 2023-6-4 0:15:26

                            题目:

                            给出三各定点的坐标,求出三角形的面积需要的库要有:iostream(或cstdio,根据自己喜好选择,这里以iostream为例)、cmath、iomanip。 PS:本题需要用到海伦公式(本人还没学):S=√p(p-a)(p-b)(p-c)、p=(a+b+c)/2,及两点距离公式:√(x₁-x₂)²+(y₁-y₂)²,

                            思路:

                            定义6个双精度浮点型变量

                            输入6个双精度浮点型变量的值

                            使用两点距离公式求出三条边的长</b>,并重新定义3个双精度浮点型变量储存3条边

                            定义、求出p

                            使用海伦公式求出三角形面积

                            输出

                            偷懒简化:

                            把海伦公式写在输出函数(其它就别替换进去啦,谁写一段辣么长的代码不换行、不定义变量[大喊大叫])

                            参考:

                            #include <iostream>
                            #include <iomanip>
                            #include <cmath>
                            using namespace std;
                            int main(){
                            	double x1, y1, x2, y2, x3, y3;
                            	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
                            	double a, b, c;
                            	a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
                            	b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
                            	c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
                            	double p = (a + b + c) / 2;
                            	cout << fixed << setprecision(2) << sqrt(p * (p - a) * (p - b) * (p - c));
                            	return 0;
                            }
                            
                            • 0
                              @ 2023-6-3 18:24:07

                              #include <bits/stdc++.h>

                              using namespace std;

                              int main()

                              {

                              double x1, y1, x2, y2, x3, y3;

                              cin>>x1>>y1>>x2>>y2>>x3>>y3;

                              double a=sqrt(pow(abs(x1-x2),2)+pow(abs(y1-y2),2));

                              double b=sqrt(pow(abs(x1-x3),2)+pow(abs(y1-y3),2));

                              double c=sqrt(pow(abs(x2-x3),2)+pow(abs(y2-y3),2));

                              double p=(a+b+c)/2;

                              double S=sqrt(p*(p-a)(p-b)(p-c));

                              printf("%.2lf",S)

                              return 0;

                              }

                              • 0
                                @ 2023-6-3 10:27:06

                                思路: 获取每个点的坐标以后,按照P0008的思路(勾股定理,用两点的x,y坐标相减得到两边长度,再用a² + b² = c²求出c²,最后用sqrt()求出c的长度)求出三边长度,用abs()以防出现负数,然后将a,b,c代入海伦公式求出p的值,最后将a,b,c,p代入海伦公式求面积

                                #include <iostream>
                                #include <cmath>
                                #include <iomanip>
                                using namespace std;
                                
                                int main()
                                {
                                    double x1,y1,x2,y2,x3,y3,a,b,c,p;
                                    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
                                    a = sqrt(pow(abs(x1 - x2),2) + pow(abs(y1 - y2),2));
                                    b = sqrt(pow(abs(x1 - x3),2) + pow(abs(y1 - y3),2));
                                    c = sqrt(pow(abs(x2 - x3),2) + pow(abs(y2 - y3),2));
                                    p = (a + b + c) / 2.0;
                                    cout << fixed << setprecision(2) << sqrt(p * (p - a) * (p - b) * (p - c));
                                    return 0;
                                }
                                
                                • 1

                                信息

                                ID
                                123
                                时间
                                1000ms
                                内存
                                128MiB
                                难度
                                6
                                标签
                                递交数
                                3156
                                已通过
                                993
                                上传者