题目描述

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. 20135208 JAVA第三次实验

    课程:Java实验   班级:201352     姓名:贺邦  学号:20135208 成绩:             指导教师:娄佳鹏   实验日期:15.06.03 实验密级:         ...

  2. 20162316刘诚昊 第八周实验报告:实验二 Java面向对象程序设计

    实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验要求 1.没有Linux基础的同学建议先学习<L ...

  3. snprintf vs sprintf

    #include <stdio.h> int printf(const char *format, ...); int fprintf(FILE *stream, const char * ...

  4. 《JavaScript》JS中的跨域问题

    参考博客:https://www.cnblogs.com/yongshaoye/p/7423881.html

  5. C++:构造函数1——普通构造函数

    前言:构造函数是C+中很重要的一个概念,这里对其知识进行一个简单的总结 一.构造函数的定义 1.类中的构造函数名与类名必须相同 2.构造函数没有函数的返回类值型说明符 [特别注意]: a.构造函数的返 ...

  6. 18软工实践-第八次作业(课堂实战)-项目UML设计(团队)

    目录 团队信息 分工选择 课上分工 课下分工 ToDolist alpha版本要做的事情 燃尽图 UML 用例图 状态图 活动图 类图 部署图 实例图 对象图 时序图 包图 通信图 贡献分评定 课上贡 ...

  7. Java 更改日期格式

    import java.util.*; import java.text.*; public class TestDateFormat { public static void main(String ...

  8. RequestMappingHandlerMapping 详解

    我们先理简单梳理一个关系 关系梳理 spring ioc 是spring的核心,用来管理spring bean的生命周期 MVC 是一种使用 MVC(Model View Controller 模型- ...

  9. QList和QVector使用

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QList和QVector使用     本文地址:http://techieliang.com ...

  10. eclipse官方网址、各个版本的下载

    Eclipse3.1后各版本代号 (2013-07-10 20:48:42) 转载▼   分类: Java Eclipse 3.1 版本代号 IO [木卫1,伊奥]  Eclipse 3.2 版本代号 ...