题目描述

Arty has been an abstract artist since childhood, and his works have taken on many forms. His latest (and most pricey) creations are lovingly referred to as Abstract Art within the abstract art community (they’re not the most original bunch when it comes to loving nicknames). Here’s an example of one of Arty’s recent works:

As you can see, Abstract Art is created by painting (possibly overlapping) polygons. When Arty paints one of his designs he always paints each polygon completely before moving on to the next one. 
The price of individual pieces of Arty’s Abstract Art varies greatly based on their aesthetic appeal, but collectors demand two pieces of information about each painting: 
1. the total amount of paint used, and
2. the total amount of canvas covered.
Note that the first value will be larger than the second whenever there is overlap between two or more polygons. Both of these values can be calculated from a list containing the vertices of all the polygons used in the painting, but Arty can’t waste his time on such plebeian pursuits — he has great art to produce! I guess it’s left up to you.

输入

The first line of input contains a single integer n (1 ≤ n ≤ 100) representing the number of polygons to be painted. Following this are n lines each describing a painted polygon. Each polygon description starts with an integer m (3 ≤ m ≤ 20) indicating the number of sides in the polygon, followed by m pairs of integers x y (0 ≤ x, y ≤ 1 000) specifying the coordinates of the vertices of the polygon in consecutive order. Polygons may be concave but no polygon will cross itself. No point on the canvas will be touched by more than two polygon border segments.

输出

Display both the total amount of paint used and the amount of canvas covered. Your answers must have a relative or absolute error of at most 10−6.

样例输入

3
8 7 10 7 17 10 20 17 20 20 17 20 10 17 7 10 7
4 0 0 0 8 8 8 8 0
4 3 3 3 13 13 13 13 3

样例输出

315.00000000 258.50000000
一堆多边形的面积的并
存个板子
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+;
const double eps=1e-;
int m;
double ans1,ans2;
int sgn(double x)
{
if (fabs(x)<eps) return ;
return x<?-:;
}
struct Point{
double x,y;
Point(){}
Point(double _x,double _y)
{
x=_x; y=_y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x+y*b.y;
} };
struct Polygon
{
int n;
Point p[];
void input()
{
for (int i=;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
p[n]=p[];
}
double area()
{
double res=;
for (int i=;i<n;i++) res+=p[i]^p[(i+)%n];
return res/2.0;
}
Point& operator[](int idx)
{
return p[idx];
}
}v[];
double cross(Point o,Point a,Point b)
{
return (a-o)^(b-o);
}
double seg(Point o,Point a,Point b)
{
if (sgn(b.x-a.x)==) return (o.y-a.y)/(b.y-a.y);
return (o.x-a.x)/(b.x-a.x);
}
pair<double,int>s[N];
double PolygonUnion()
{
int M,c1,c2;
double s1,s2,ret=;
for (int i=;i<m;i++)
{
for (int ii=;ii<v[i].n;ii++)
{
M=;
s[M++]=make_pair(0.00,);
s[M++]=make_pair(1.00,);
for (int j=;j<m;j++) if(j!=i)
{
for (int jj=;jj<v[j].n;jj++)
{
c1=sgn(cross(v[i][ii],v[i][ii+],v[j][jj]));
c2=sgn(cross(v[i][ii],v[i][ii+],v[j][jj+]));
if (c1== && c2==)
{
if (((v[i][ii+]-v[i][ii])*(v[j][jj+]-v[j][jj]))> && i>j)
{
s[M++]=make_pair(seg(v[j][jj],v[i][ii],v[i][ii+]),);
s[M++]=make_pair(seg(v[j][jj+],v[i][ii],v[i][ii+]),-);
}
}
else
{
s1=cross(v[j][jj],v[j][jj+],v[i][ii]);
s2=cross(v[j][jj],v[j][jj+],v[i][ii+]);
if (c1>= && c2<) s[M++]=make_pair(s1/(s1-s2),);
else if (c1< && c2>=) s[M++]=make_pair(s1/(s1-s2),-);
}
}
}
sort(s,s+M);
// for (int i=0;i<M;i++) cout<<s[i].first<<' '<<s[i].second<<endl;
double pre=min(max(s[].first,0.0),1.0),now;
double sum=;
int cov=s[].second;
for (int j=;j<M;j++)
{
now=min(max(s[j].first,0.0),1.0);
if (!cov) sum+=now-pre;
cov+=s[j].second;
pre=now;
}
ret+=(v[i][ii]^v[i][ii+])*sum;
}
}
return ret/;
} int main()
{
scanf("%d",&m);
for(int i=;i<m;i++)
{
scanf("%d",&v[i].n);
v[i].input();
double nows=v[i].area();
if (sgn(nows<))
{
reverse(v[i].p,v[i].p+v[i].n);
nows*=-;
v[i][v[i].n]=v[i][];
}
ans1+=nows;
}
// cout<<'*'<<endl;
ans2=PolygonUnion();
printf("%.8f %.8f\n",ans1,ans2);
return ;
}
 

ECNA-A- Abstract Art的更多相关文章

  1. GYM 101673 A - Abstract Art 多个一般多边形面积并

    A - Abstract Art #include<bits/stdc++.h> #define LL long long #define fi first #define se seco ...

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

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

  3. ECNA 2017

    ECNA 2017 Abstract Art 题目描述:求\(n\)个多边形的面积并. solution 据说有模板. Craters 题目描述:给定\(n\)个圆,求凸包的周长. solution ...

  4. Gerald is into Art

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

  5. 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/ ...

  6. CodeForces 560B Gerald is into Art

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

  7. 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 ...

  8. B. Gerald is into Art

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

  9. Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)

    A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef lo ...

  10. 2017-2018 ACM-ICPC East Central North America Regional Contest (ECNA 2017) Solution

    A:Abstract Art 题意:给出n个多边形,求n个多边形分别的面积和,以及面积并 思路:模板 #include <bits/stdc++.h> using namespace st ...

随机推荐

  1. php判断是否https

    function is_https() { if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'o ...

  2. c 用指针操作结构体数组

    重点:指针自加,指向下一个结构体数组单元 #include <stdio.h> #include <stdlib.h> #include <string.h> #d ...

  3. php面试必知必会常见问题

    1 说出常用的10个数组方法 我觉得数组比较最能体现PHP基础语法的一个数据结构了,下面给大家列一下常用的10个关于操作数组的函数 in_array(判断数组中是否有某个元素) implode(将数组 ...

  4. 【数据库】mysql中复制表结构的方法小结

    mysql中用命令行复制表结构的方法主要有一下几种: 1.只复制表结构到新表 ? 1 CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2 或者 ? 1 CREATE ...

  5. 【JavaScript&jQuery】返回顶部

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. Redis windows环境安装 以及 redis整合spring

    Redis对于Linux是官方支持的,安装和使用没有什么好说的,普通使用按照官方指导,5分钟以内就能搞定.详情请参考: http://redis.io/download Redis官方是不支持wind ...

  7. 管理与技术未必不可兼得,一个20年IT老兵的码农生涯

    作者|康德胜 我是一个喜欢写代码但几乎不太有机会写代码的CTO,也是一个看得懂财务报表.通过所有CFA(金融特许分析师)考试并获得FRM(金融风险经理)认证的拿到金融MBA的CTO,如果我有幸被称作码 ...

  8. P1054 等价表达式

    题目描述 明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代数表达式,然后列出了若干选项,每个选项也是一个代数表达式,题目的要求是判断选项中哪些代数 ...

  9. 【HDU4336】Card Collector (动态规划,数学期望)

    [HDU4336]Card Collector (动态规划,数学期望) 题面 Vjudge 题解 设\(f[i]\)表示状态\(i\)到达目标状态的期望 \(f[i]=(\sum f[j]*p[j]+ ...

  10. BZOJ3295:[CQOI2011]动态逆序对——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=3295 Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数 ...