A - Abstract Art

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); struct Point {
double x, y;
Point(double x = , double y = ) : x(x), y(y) { } };
typedef Point Vector;
int dcmp(double x) {
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
Point operator + (Vector A, Vector B) {return Point(A.x + B.x, A.y + B.y);}
Point operator - (Vector A, Vector B) {return Point(A.x - B.x, A.y - B.y);}
Point operator * (Vector A, double p) {return Point(A.x * p, A.y * p);}
Point operator / (Vector A, double p) {return Point(A.x / p, A.y / p);}
bool operator < (const Vector &A, const Vector &B) {return A.y < B.y || (A.y == B.y && A.x < B.x);}
bool operator == (const Vector &A, const Point &B) {return dcmp(A.x - B.x) == && dcmp(A.y - B.y) == ;}
double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;}
double Length(Vector A) {return sqrt(Dot(A, A));}
double Angle(Vector A, Vector B) {return acos(Dot(A, B) / Length(A) / Length(B));}
double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;}
double Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);} double PolygonArea(vector<Point>& p) {
int n = p.size();
double area = ;
for(int i = ; i < n - ; i++)
area += Cross(p[i]-p[], p[i+]-p[]);
return fabs(area / );
} double Seg(Point O, Point A, Point B){
if(dcmp(B.x - A.x) == ) return (O.y - A.y) / (B.y - A.y);
return (O.x - A.x) / (B.x - A.x);
} double MultiPolyArea(vector<Point>* p, int n) {
double res=;
vector<pair<double, int>> s;
for(int i = ; i < n; i++) {
int sz = p[i].size();
for(int j = ; j < sz; j++){
s.clear();
s.push_back(mk(, ));
s.push_back(mk(, ));
Point a = p[i][j], b = p[i][(j+)%sz];
for(int k = ; k < n; k++){
if(i != k){
int sz2 = p[k].size();
for(int z = ; z < sz2; z++){
Point c = p[k][z], d = p[k][(z+)%sz2];
int c1 = dcmp(Cross(b-a, c-a));
int c2 = dcmp(Cross(b-a, d-a));
if(c1 == && c2 == ) {
if(dcmp(Cross(b-a, d-c))) {
s.push_back(mk(Seg(c, a, b), ));
s.push_back(mk(Seg(c, a, b), -));
}
} else {
double s1 = Cross(d-c, a-c), s2 = Cross(d-c, b-c);
if(c1 >= && c2 < ) s.push_back(mk(s1/(s1-s2), ));
else if(c1 < && c2 >= ) s.push_back(mk(s1/(s1-s2), -));
}
}
}
}
sort(s.begin(), s.end());
double pre = min(max(s[].fi, 0.0), 1.0), now, sum=;
int cov = s[].se;
for(int j = ; j < s.size(); j++) {
now = min(max(s[j].fi, 0.0), 1.0);
if(!cov) sum += now - pre;
cov += s[j].second;
pre = now;
}
res += Cross(a, b) * sum;
}
}
return fabs(res / );
} int n, m;
vector<Point> poly[]; int main() {
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%d", &m);
poly[i].resize(m);
for(int j = ; j < m; j++) {
scanf("%lf%lf", &poly[i][j].x, &poly[i][j].y);
}
}
double ans1 = , ans2 = MultiPolyArea(poly, n);
for(int i = ; i < n; i++) ans1 += PolygonArea(poly[i]);
printf("%.12f %.12f\n", ans1, ans2);
return ;
} /*
*/

GYM 101673 A - Abstract Art 多个一般多边形面积并的更多相关文章

  1. Gym - 101673:B Craters (几何,求凸包)

    题意:给定几个圆,求最短的围合,把这几个包围起来,而且到圆的距离都不小于10. 思路:把每个圆的半径+10,边等分5000份,然后求凸包即可. #include<bits/stdc++.h> ...

  2. Gym-101673: A Abstract Art (模板,求多个多边形的面积并)

    手抄码板大法. #include<bits/stdc++.h> using namespace std; #define mp make_pair typedef long long ll ...

  3. Gym - 101208J 2013 ACM-ICPC World Finals J.Pollution Solution 圆与多边形面积交

    题面 题意:给你一个半圆,和另一个多边形(可凹可凸),求面积交 题解:直接上板子,因为其实这个多边形不会穿过这个半圆,所以他和圆的交也就是和半圆的交 打的时候队友说凹的不行,不是板题,后面想想,圆与多 ...

  4. POJ 1279 Art Gallery 半平面交/多边形求核

    http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...

  5. POJ 1279 Art Gallery 半平面交 多边形的核

    题意:求多边形的核的面积 套模板即可 #include <iostream> #include <cstdio> #include <cmath> #define ...

  6. Gerald is into Art

    Gerald is into Art Gerald bought two very rare paintings at the Sotheby's auction and he now wants t ...

  7. Codeforces Round #313 (Div. 2)B.B. Gerald is into Art

    B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/ ...

  8. CodeForces 560B Gerald is into Art

     Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #313 (Div. 2) B. Gerald is into Art 水题

    B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/560 ...

随机推荐

  1. DotNetBar 中Ribbon汉化

    private void frmMain_Load(object sender, System.EventArgs e)        {            //  Ribbon汉化代码      ...

  2. 在ASP.Net环境中,当用户点击报表中的超链接时如何调用Java Script方法?

    问题描述:在ASP.Net环境中,当用户点击报表中的超链接时如何调用Java Script方法? 问题解答: 你可以在TextObject.Hyperlink对象中编写js代码(javascript: ...

  3. MySQL5.7主从复制配置

    1 my.cnf文件 配置 binlog_format = ROW log_bin_trust_function_creators=1 log-error = /usr/local/mysql/dat ...

  4. vue插件开发实践与要点

    其实就跟组件差不多意思,组件也可以实现相关的效果,但要在用到的地方都引用插件就可以全局注册,不需引用 试着撸一个插件,有2个功能,提示和对话框 网上找了个toast插件的代码,改了改,扩展加了个dia ...

  5. 复习python

    1当命令行键入python a.py的方式运行python程序时候,a.py不需要执行权,当已./a.py运行时,需要执行权 2.与c语言不同的地方 i = 3 print (i)#合法 #在pyth ...

  6. Go 语言读书笔记

    Go语言的设计理念很明确,就是将动态类型语言的编程容易度和静态类型语言的安全效率结合起来.     Go语言,又称Golang,是Google开发的一款静态强类型.编译型.并发型,并具有垃圾回收机制的 ...

  7. mysql 查询优化~sql优化通用

    一 简介:今天我们来探讨下SQL语句的优化基础 二 基础规则: 一 通用: 1 避免索引字段使用函数     2 避免发生隐式转换     3 order by字段需要走索引,否则会发生filesor ...

  8. python - wmi模块学习(windwos硬件信息获取)

    获取windows操作系统的硬件信息 #!/usr/bin/env python # -*- coding: utf-8 -*- # http://www.cnblogs.com/liu-ke/ im ...

  9. numpy中 array数组的shape属性

    numpy.array 的shape属性理解 在码最邻近算法(K-Nearest Neighbor)的过程中,发现示例使用了numpy的array数组管理,其中关于array数组的shape(状态)属 ...

  10. sqlyog通过跳板机ssh连接mysql数据库

    方法一: 方法二: 在跳板机上启动sh脚本做ssh端口转发,客户端配置连接 10.0.0.1的8306端口即可 jdbc:mysql://10.0.0.1:8306/testdb?useUnicode ...