多边形面积(Area_Of_Polygons)
原理:
任意多边形的面积可由任意一点与多边形上依次两点连线构成的三角形矢量面积求和得出。
分析:
由于给出的点是相对于我们的坐标原点的坐标,每个点实际上我们可以当作一个顶点相对于原点的向量,如下图所示:

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)的更多相关文章
- [知识点]计算几何I——基础知识与多边形面积
// 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...
- 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping
题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...
- 三角剖分求多边形面积的交 HDU3060
//三角剖分求多边形面积的交 HDU3060 #include <iostream> #include <cstdio> #include <cstring> #i ...
- CF 107E 多边形面积并
107E Darts 题目:给出n个矩形,问落在n个矩形交的部分的概率 分析:裸的多边形面积并. 代码略..
- POJ1265——Area(Pick定理+多边形面积)
Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...
- poj 1654 Area 多边形面积
/* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...
- [ECNU 1624] 求交集多边形面积
求交集多边形面积 Time Limit:1000MS Memory Limit:30000KB Total Submit:98 Accepted:42 Description 在平面上有两给定的凸多边 ...
- Area - POJ 1654(求多边形面积)
题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...
随机推荐
- TCP层accept系统调用的实现分析
inet_csk_accept函数实现了tcp协议accept操作,其主要完成的功能是,从已经完成三次握手的队列中取控制块,如果没有已经完成的连接,则需要根据阻塞标记来来区分对待,若非阻塞则直接返回, ...
- java实现一个简单的验证码生成器
最近看了网上很多大佬们写的验证码生成,寻思着自己也写一个,话不多说,代码如下: import java.awt.BasicStroke; import java.awt.Color; import j ...
- SqlHelper 类
// 一个自用的 SqlHelper 类 利用了刚学习到的 扩展方法 http://technet.microsoft.com/zh-cn/bb383977 /// <summary> / ...
- 域名到IP 报错socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Python中如何通过域名,查看对应的IP? 请看如下代码: import socket hostname="www.baidu.com" ip = socket.gethostb ...
- leetcode131分割回文串
class Solution { public: vector<vector<string>> ans; bool isok(string s){ ; ; while(i< ...
- LC 648. Replace Words
In English, we have a concept called root, which can be followed by some other words to form another ...
- [SQL]学习中遇到的错误
1.中英文模式切换 查找语句中不能出现中文字符!!!
- centos 7 删除 virbr0 虚拟网卡
出现虚拟网卡是因为安装时启用了 libvirtd 服务后生成的关闭方法virsh net-list名称 状态 自动开始 持久------------------- ...
- 自在因梦 | 威爾伯的Fourth Turning所引發的聯想
2015-05-06 胡因梦 ...
- C基础知识(3):指针--概念、数组中指针的递增/递减、指针数组&数组指针、指向指针的指针
指针是一个变量,其值为另一个变量的地址. 所有指针的值的实际数据类型,不管是整型.浮点型.字符型,还是其他的数据类型,都是一样的,都是一个代表内存地址的长的十六进制数. 下面从4个代码例子分别讲述以下 ...