原理:

任意多边形的面积可由任意一点与多边形上依次两点连线构成的三角形矢量面积求和得出。

分析: 
由于给出的点是相对于我们的坐标原点的坐标,每个点实际上我们可以当作一个顶点相对于原点的向量,如下图所示:


 
P(0,0)对应的顶点向量分别为:A(x0,y0),B(x1,y1),…,G(x6,y6) 
另外,△PAB△PAB的矢量面积即为


且多边形面积为:


根据上述公式可以直接求出多边形的代码从而避免了边长的复杂计算。

例题:

https://ac.nowcoder.com/acm/contest/328/F

题解:计算几何裸题

#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=+;
const int MOD=1e9+;
const double PI = acos(-1.0);
const double EXP = 1E-;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
double ans;
struct node{
double x,y; }e[N];
double a[N];
char str;
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
scanf("%d%d",&n,&q);
if(n==){
printf("%.6f",ans);
return ;
}
for(int i=;i<=n;i++){
scanf("%lf%lf",&e[i].x,&e[i].y);
}
for(int i=;i<=n;i++){
if(n==)
a[i]=a[i-]+e[i].y*e[n].x-e[i].x*e[n].y;
else
a[i]=a[i-]+e[i].y*e[i-].x-e[i].x*e[i-].y;
}
double sum=fabs(a[n]/);
//cout<<sum<<endl;
int s,t;
while(q--){
scanf("%d%d",&s,&t); if(s>t)
swap(s,t);
if(abs(s-t)==||s==&&t==n)
continue;
double sumtmp=fabs((a[t]-a[s]+e[s].y*e[t].x-e[s].x*e[t].y)/);
ans=max(ans,min(sumtmp,sum-sumtmp));
}
printf("%.6f",ans);
//cout << "Hello world!" << endl;
return ;
}

C++版本二

题解:

计算几何
只要叉积维护一下前缀和就好了。

#include <cstdio>
#include <bits/stdc++.h>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--) typedef long long ll;
const int maxn = ;
const ll INF = 1e18;
const ll mod=1e9+;
const double eps = 1e-; int n,m; struct node
{
double x,y;
}a[maxn]; double sum[maxn]; double cross(node a,node b,node c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
}
node zero;
zero.x=;
zero.y=;
for(int i=;i<=n;i++)
{
double ans=cross(zero,a[i],a[(i==n?:i+)]);
sum[i]=sum[i-]+ans;
}
for(int i=n+;i<=*n;i++)
{
sum[i]=sum[i-]+sum[i-n];
}
double Sum=fabs(sum[n])/2.0;
double cnt=;
for(int i=;i<m;i++)
{
int ss,tt;
scanf("%d%d",&ss,&tt);
if(ss>tt) swap(ss,tt);
double ans=sum[tt-]-sum[ss-];
ans+=cross(zero,a[tt],a[ss]);
ans=fabs(ans)/2.0;
cnt=max(cnt,min(ans,Sum-ans));
}
printf("%.15f\n",cnt);
}

多边形面积(Area_Of_Polygons)的更多相关文章

  1. [知识点]计算几何I——基础知识与多边形面积

    // 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...

  2. 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping

    题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...

  3. 三角剖分求多边形面积的交 HDU3060

    //三角剖分求多边形面积的交 HDU3060 #include <iostream> #include <cstdio> #include <cstring> #i ...

  4. CF 107E 多边形面积并

    107E Darts 题目:给出n个矩形,问落在n个矩形交的部分的概率 分析:裸的多边形面积并. 代码略..

  5. POJ1265——Area(Pick定理+多边形面积)

    Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...

  6. poj 1654 Area 多边形面积

    /* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...

  7. [ECNU 1624] 求交集多边形面积

    求交集多边形面积 Time Limit:1000MS Memory Limit:30000KB Total Submit:98 Accepted:42 Description 在平面上有两给定的凸多边 ...

  8. Area - POJ 1654(求多边形面积)

    题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...

  9. poj3348 Cows 凸包+多边形面积 水题

    /* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...

随机推荐

  1. pl/sql 过程 函数(写一个过程,输入部门编号,在控制台打印这个部门的名称,总人数,平均工资(基本工资+奖金))

    1.编写过程,输入三角形三个表的长度.在控制台打印三角形的面积. create or replace procedure pro_s(v_a number,v_b number,v_c number) ...

  2. JVM 监控工具——jstatd

    1. 简介 jstatd是一个rmi的server应用,用于监控jvm的创建和结束,并且提供接口让监控工具(如visualvm)可以远程连接到本机的jvms . 注意是jvms,就是说运行jstatd ...

  3. beta week 2/2 Scrum立会报告+燃尽图 03

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9956 一.小组情况 组长:贺敬文组员:彭思雨 王志文 位军营 徐丽君队名: ...

  4. VS Code 调试 Golang 出现 Failed to continue: Check the debug console for details

    VS Code断点调试Golang时候,弹出提示:Failed to continue: Check the debug console for details 点击Open launch.json, ...

  5. 转贴 使用正则表达式解析一般sql语句(C++)

    https://blog.csdn.net/dreamgchuan/article/details/47715743 --END--2019年9月5日11点58分

  6. APT软件包管理-在线安装

    APT (Advanced Packaging Tool高级软件包工具) 是一个强大的包管理系统,而那些图形化程序如 添加/删除 应用程序 都是建立 在它的基础之上的.有了dpkg后,Debian再次 ...

  7. Linux 通道

    简单地说,一个通道接受一个工具软件的输出,然后把那个输出输入到其它工具软件.使用UNIX/Linux的词汇,这个通道接受了一个过程的标准输出,并把这个标准的输出作为另一个过程的标准输入.如果你没有重新 ...

  8. 修改Android EditText光标颜色和底线颜色

    1.修改光标颜色 EditText有一个属性:android:textCursorDrawable,这个属性是用来控制光标颜色的android:textCursorDrawable="@nu ...

  9. wpf prism IRegionManager 和IRegionViewRegistry

    引入了一个新的问题,IRegionViewRegistry和IRegionManager都具有RegisterViewWithRegion方法,二者有区别么? 答案是——没有.我们已经分析过,在Uni ...

  10. layui 数据表格复选框实现单选功能

    //点击选中(单选)//单击行勾选checkbox事件 $(document).on("click",".layui-table-body table.layui-tab ...