Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积

Maximal Area Quadrilateral CodeForces - 340B

三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置):

http://www.cnblogs.com/xiexinxinlove/p/3708147.html

https://jingyan.baidu.com/article/a65957f49596ab24e67f9be7.html

枚举对角线,求出在对角线两侧取任意点能得到的三角形的面积,然后对于每条对角线,最大值就是两侧面积最大值之和。

 1 #include<cstdio>
 2 #include<algorithm>
 3 using std::max;
 4 #include<cmath>
 5 using std::abs;
 6 #define inf 20000000.0
 7 int n;
 8 double x[310],y[310],a[2],anss,mj1;
 9 double mj(double x1,double y1,double x2,double y2,double x3,double y3)
10 {
11     return ((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1))/2;
12 }
13 int main()
14 {
15     int i,j,k;
16     scanf("%d",&n);
17     for(i=1;i<=n;i++)
18         scanf("%lf%lf",&x[i],&y[i]);
19     for(i=1;i<=n;i++)
20         for(j=i+1;j<=n;j++)
21         {
22             a[0]=a[1]=-inf;
23             for(k=1;k<=n;k++)
24             {
25                 if(k==i||k==j)    continue;
26                 mj1=mj(x[i],y[i],x[j],y[j],x[k],y[k]);
27                 a[mj1>0]=max(a[mj1>0],abs(mj1));
28             }
29             anss=max(anss,a[0]+a[1]);
30         }
31     printf("%lf",anss);
32     return 0;
33 }
时间: 2024-08-10 07:04:18

Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积的相关文章

【c语言】给出三角形的三边长,求三角形面积

// 给出三角形的三边长,求三角形面积 // area = sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) ) // s = ( a + b + c) / 2 #include <stdio.h> #include <math.h> int main() { int a,b,c; double s,area; printf("请输入三角形三个边长:"); scanf("%d%d%d",&a,&a

已知三点,求三角形面积

已经知道三角形三点A(X1,Y1) B(X2,Y2) C(X3,Y3) \[ \vec{AB} = (X2-X1,Y2-Y1) \] \[ \vec{AC} = (X3-X1,Y3-Y1) \] \[ ||n|| = \vec{AB} \times \vec{AC} = |\vec{AB}|\cdot|\vec{AB}|*Sin<\vec{AB},\vec{AC}> \] \[ 因为 |\vec{AB}|*Sin<\vec{AB},\vec{AC}> 为三角形的高 \] \[ 所以

MT【12】三点坐标求面积

$L_1,L_2$是O发出的两条射线,C是一个常数,一条动直线$l$分别与$L_1,L_2$交于A,B两点.$S_{\Delta ABC}=C$,求A,B的中点D的轨迹方程.(2012北大自主招生) 评:如果知道行列式的相关知识,可以由坐标直接求线段长,面积以及体积.

【TOJ 2034】C++实验:面积排序(已知三点,利用二阶行列式求三角形面积)

描述 给定三角形.矩形.圆等二维几何图形,请根据面积从大到小进行排序. 主函数里的代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { vector<CShape*> vec; //为了使用多态,使用指针数组 string name; int num[3]= {}; //用于存储3种形状的ID while(cin>>name) { if(name=="rectangle") { CPoint p1, p2; cin>>p

Maven 系列 三 :坐标和依赖

1 . 坐标 maven 的所有构件均通过坐标进行组织和管理.maven 的坐标通过 5 个元素进行定义,其中 groupId.artifactId.version 是必须的,packaging 是可选的(默认为jar),classifier 是不能直接定义的. groupId:定义当前 Maven 项目所属的实际项目,跟 Java 包名类似,通常与域名反向一一对应. artifactId:定义当前 Maven 项目的一个模块,默认情况下,Maven 生成的构件,其文件名会以 artifactI

三边测量法:通过三点坐标和到三点的距离,返回第4点位置

public class IBeaconLocation { //计算手机与蓝牙基站的距离 public static double calculateAccuracy(iBeaconClass.iBeacon beacon) { int txPower = beacon.txPower; double rssi = beacon.rssi; if (rssi == 0) { return -1.0; // if we cannot determine accuracy, return -1.

Scala实现:已知三点坐标,求最短距离(如果在垂足不在线段内,最短距离为到其中一点的直线距离)

/** * 已知三点坐标,求其中一点到另两点的垂线距离 * (如果在垂足不在线段内,最短距离为到其中一点的直线距离) * Created by wzq on 17-11-2. */object Point2lineDistance { def main(args: Array[String]) { val v: Double = pointToLine(-3, 0, 3, 0, 0, 3) System.out.println(v) } def pointToLine(x1: Int, y1:

线段树 : 求矩形面积的并 ---- hnu : 12884 Area Coverage

Area Coverage Time Limit: 10000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 16, Accepted users: 12 Problem 12884 : No special judgement Problem description In this day and age, a lot of the spying on other countries is done

84. Largest Rectangle in Histogram *HARD* 柱状图求最大面积 85. Maximal Rectangle *HARD*

1. Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]. The large