题目描述

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. Polycarp and Letters(set首战!)

    Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...

  2. 复利计算器4.0之再遇JUnit

    复利计算器4.0之再遇JUnit 前言    虽然之前的复利计算器版本已经尝试过使用JUnit单元测试,但由于没有系统性地学习过JUnit的使用,用得并不好,主要问题表现在测试的场景太少,并没有达到测 ...

  3. 福大软工1816:Beta总结

    第三视角Beta答辩总结 博客链接以及团队信息 组长博客链接 成员信息(按拼音排序) 姓名 学号 备注 张扬 031602345 组长 陈加伟 031602204 郭俊彦 031602213 洪泽波 ...

  4. CentOS 7 安装 MySql 8

    1-安装 CentOS 7   2-安装 NETCORE SDK      SDK 安装文档:https://dotnet.microsoft.com/download/linux-package-m ...

  5. Mac10.11.2 Apache 服务配置

    系统默认是隐藏apache安装目录的,但我们可以通过“命令行”或者“文件夹前往”的方式找到它.它是安装在系统的私有目录下,也就是/private/etc下面,因为它是隐藏的,所以我们无法通过界面找到它 ...

  6. 0302思考IT行业的感想

    在看完这两篇报道IT行业的报道后,可以看出IT行业在整个就业行业中是一个十分热门的行业,而且薪酬也相对较高,企业对于各种IT人才的需求很大,意味着就业的面较宽且就业的前景比较乐观.但是随之而来的问题是 ...

  7. BETA预发布演示视频

    视频连接:优酷http://v.youku.com/v_show/id_XMTgxMjQxMjc0NA==.html?from=y1.7-2

  8. CentOS7 修改分辨率

    1. 修改文件: vi /boot/grub2/grub.cfg 2. 在linux16 开头的哪一行 增加 vga=0x341 修改为1024x768 3. 重启..

  9. MySql中的varchar类型

    转载:http://www.cnblogs.com/doit8791/archive/2012/05/28/2522556.html 1.varchar类型的变化 MySQL 数据库的varchar类 ...

  10. mysql项目路径URL编码

    jdbc_url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useUnicode=true&characterEncodi ...