Luogu-4196 [CQOI2006]凸多边形
凸多边形的面积就相当于半平面交
求几个凸多边形面积交就相当于一堆半平面一起求交
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e3+100;
struct Point{
double x,y;
Point(double xx=0,double yy=0){
x=xx,y=yy;
}
}a[maxn],p[maxn];
struct Vector{
double x,y;
Vector(double xx=0,double yy=0){
x=xx,y=yy;
}
};
struct Line{
Point p;
Vector v;
double ang;
Line(Point a=Point(),Vector b=Vector()){
p=a,v=b;
ang=atan2(v.y,v.x);
}
}q[maxn],b[maxn];
int dcmp(double x){return fabs(x)<1e-9?0:(x>0?1:-1);}
Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
Point operator + (Point a,Vector b){return Point(a.x+b.x,a.y+b.y);}
Vector operator * (double p,Vector a){return Vector(a.x*p,a.y*p);}
double operator * (Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double operator * (Point a,Point b){return a.x*b.y-a.y*b.x;}
bool operator < (Line x,Line y){return dcmp(x.ang-y.ang)==0?(dcmp(x.v*(y.p-x.p))>0):(x.ang<y.ang);}
Point glt(Line x,Line y){Vector v=x.p-y.p; return x.p+(y.v*v)/(x.v*y.v)*x.v;}
bool onright(Line a,Line b,Line t){Point p=glt(a,b); return dcmp(t.v*(p-t.p))<0;}
void bpm(Line *b,int &n,Point *p){
sort(b+1,b+n+1);
int l=0,r=1,tot=0;
for(int i=1;i<=n;i++){
if(b[i].ang!=b[i-1].ang) tot++;
b[tot]=b[i];
}
n=tot,q[0]=b[1],q[1]=b[2];
for(int i=3;i<=n;i++){
while(l<r&&onright(q[r],q[r-1],b[i])) r--;
while(l<r&&onright(q[l],q[l+1],b[i])) l++;
q[++r]=b[i];
}
while(l<r&&onright(q[r],q[r-1],q[l])) r--;
while(l<r&&onright(q[l],q[l+1],q[r])) l++;
n=0,q[r+1]=q[l];
for(int i=l;i<=r;i++)
b[++n]=q[i],p[n]=glt(q[i],q[i+1]);
}
double S(Point *p,int n){
double ans=0;
p[n+1]=p[1];
for(int i=1;i<=n;i++)
ans+=p[i]*p[i+1];
return fabs(ans)/2;
}
int t,m,n;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&m);
for(int i=1;i<=m;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
a[m+1]=a[1];
for(int i=1;i<=m;i++)
b[++n]=Line(a[i],a[i+1]-a[i]);
}
bpm(b,n,p);
printf("%.3lf\n",S(p,n));
return 0;
}
Luogu-4196 [CQOI2006]凸多边形的更多相关文章
- 【BZOJ 2618】 2618: [Cqoi2006]凸多边形 (半平面交)
2618: [Cqoi2006]凸多边形 Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. Input 第一 ...
- bzoj 2618 2618: [Cqoi2006]凸多边形(半平面交)
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 656 Solved: 340[Submit][Status] ...
- bzoj 2618: [Cqoi2006]凸多边形 [半平面交]
2618: [Cqoi2006]凸多边形 半平面交 注意一开始多边形边界不要太大... #include <iostream> #include <cstdio> #inclu ...
- 【BZOJ2618】[CQOI2006]凸多边形(半平面交)
[BZOJ2618][CQOI2006]凸多边形(半平面交) 题面 BZOJ 洛谷 题解 这个东西就是要求凸多边形的边所形成的半平面交. 那么就是一个半平面交模板题了. 这里写的是平方的做法. #in ...
- 2018.07.04 BZOJ 2618 Cqoi2006凸多边形(半平面交)
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MB Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n ...
- 洛谷 P4196 [CQOI2006]凸多边形 (半平面交)
题目链接:P4196 [CQOI2006]凸多边形 题意 给定 \(n\) 个凸多边形,求它们相交的面积. 思路 半平面交 半平面交的模板题. 代码 #include <bits/stdc++. ...
- bzoj2618: [Cqoi2006]凸多边形
Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. Input 第一行有一个整数n,表示凸多边形的个数,以下依 ...
- BZOJ2618[Cqoi2006]凸多边形——半平面交
题目描述 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. 输入 第一行有一个整数n,表示凸多边形的个数,以下依次描述各个多边形.第 ...
- LG4196 [CQOI2006]凸多边形
题意 题目描述 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. 输入输出格式 输入格式: 第一行有一个整数n,表示凸多边形的个数, ...
- P4196 [CQOI2006]凸多边形 半平面交
\(\color{#0066ff}{题目描述}\) 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. \(\color{#0066f ...
随机推荐
- linux 内存分析
http://blog.yufeng.info/archives/2456 这篇文章不错 值得看 http://www.361way.com/memory-analysis/5018.html
- Android开源--PullToRefresh
开源地址: https://github.com/chrisbanes/Android-PullToRefresh 简单介绍:PullToRefresh是一款支持ListView,GridView,V ...
- 使用AlloyLever来搞定开发调试发布,错误监控上报,用户问题定位
传送门: # gituhbhttps://github.com/AlloyTeam/AlloyLever # 官网https://alloyteam.github.io/AlloyLever/ 下载和 ...
- appearance 设置公共属性
//设置公共TabBarItem 的属性 [UITabBarItem appearance] //设置公共NavigationBar 的属性 [UIBarButtonItem appearance]
- lua学习笔记(十)
模块与包 使用require加载模块 一个规范的模块应该返回一个table作为这个模块所有导出功能的集合 lua里没通过任何强制性语法规则要求创建模块时反回一个table ...
- lua学习笔记(二)
开始 程序块chunk 交互模式里输入的一行代 一个文件里的代码 也就是一连串的语句或命令 连续的lua语句之间不需要分隔符,但也可以使用分号,如果你愿意的话 ...
- Sphinx之配置文件
# # Sphinx configuration file sample # # WARNING! While this sample file mentions all available opti ...
- 最小生成树——Kruskal(克鲁斯卡尔)算法
[0]README 0.1) 本文总结于 数据结构与算法分析, 源代码均为原创, 旨在 理解 Kruskal(克鲁斯卡尔)算法 的idea 并用 源代码加以实现: 0.2)最小生成树的基础知识,参见 ...
- WPF Button TextBox 圆角
<!--圆角button--> <Style TargetType="Button"> <Setter Property="FontSize ...
- hdu3293(pell方程+快速幂)
裸的pell方程. 然后加个快速幂. No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: ...