1 条题解

  • 3
    @ 2022-10-29 10:46:31

    叉乘

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        double xa, ya, xb, yb, xc, yc;
        cin >> xa >> ya >> xb >> yb >> xc >> yc;
        double x = xc - xa, y = yc - ya;
        double xx = xb - xa, yy = yb - ya;
        double ans = (x * yy - y * xx) / 2;
        if (ans < 0)
            ans = -ans;
        cout << fixed << setprecision(2) << ans;
        return 0;
    }
    

    海伦公式

    p=a+b+c2p=\frac{a+b+c}{2} S=p(pa)(pb)(pc)S=\sqrt{p (p-a) (p-b) (p-c)}
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	double x,y,xx,yy,xxx,yyy;
    	cin>>x>>y>>xx>>yy>>xxx>>yyy;
    	double len1=sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));
    	double len2=sqrt((x-xxx)*(x-xxx)+(y-yyy)*(y-yyy));
    	double len3=sqrt((xxx-xx)*(xxx-xx)+(yyy-yy)*(yyy-yy));
    	double p=(len1+len2+len3)/2;
    	double s=sqrt(p*(p-len1)*(p-len2)*(p-len3));
    	cout<<fixed<<setprecision(2)<<s<<endl;
    	return 0;
    }
    
    • 1

    信息

    ID
    264
    时间
    1000ms
    内存
    128MiB
    难度
    3
    标签
    (无)
    递交数
    158
    已通过
    80
    上传者