ECNA-A- Abstract Art
题目描述
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.
输入
输出
样例输入
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的更多相关文章
- GYM 101673 A - Abstract Art 多个一般多边形面积并
A - Abstract Art #include<bits/stdc++.h> #define LL long long #define fi first #define se seco ...
- Gym-101673: A Abstract Art (模板,求多个多边形的面积并)
手抄码板大法. #include<bits/stdc++.h> using namespace std; #define mp make_pair typedef long long ll ...
- ECNA 2017
ECNA 2017 Abstract Art 题目描述:求\(n\)个多边形的面积并. solution 据说有模板. Craters 题目描述:给定\(n\)个圆,求凸包的周长. solution ...
- Gerald is into Art
Gerald is into Art Gerald bought two very rare paintings at the Sotheby's auction and he now wants t ...
- 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/ ...
- CodeForces 560B Gerald is into Art
Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- B. Gerald is into Art
B. Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)
A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef lo ...
- 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 ...
随机推荐
- Knight Moves(广搜BFS)
Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to ...
- Shell脚本初学习
第一个shell程序运行,教程来自:http://jingyan.baidu.com/article/8cdccae947f83e315413cd05.html 代码如下: #!/bin/sh tou ...
- 团队Alpha冲刺(三)
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:丹丹 组员7:家伟 组员8:政演 组员9:鸿杰 组员10:刘一好 组员11:何宇恒 展示组内最 ...
- dubbo源码分析1——负载均衡
dubbo中涉及到的负载均衡算法只要有四种:Random LoadBalance(随机均衡算法).RoundRobin LoadBalance(权重轮循均衡算法).LeastAction LoadBa ...
- Spring中jdbc Template使用
http://1358440610-qq-com.iteye.com/blog/1826816
- 再谈获取网站图标Icon
上一篇文章讨论了一下获取网站图标方法,是通过从根目录直接获取和html解析结合的方式来获取的,并给出了相应的代码示例.这一篇来讨论一个更现成的方法,这个方法是从360导航的页面发现的,在导航页面中点击 ...
- day06 小数据池和编码
一. 上次课内容回顾字典:由{}括起来. 每个元素用逗号隔开, key:value的形式存储数据key: 不可变的. 可哈希的.增删改查:1. 增加: 直接用新key来赋值. dict[key] = ...
- var和let使用上的对比
var和let比较 1. let没有预解析,不存在变量提升.在代码块中,只要let定义变量,在之前使用,都是报错.先定义完再使用. let a = 12; function fn(){ alert(a ...
- canvas - 简单的神经网络
1.国际惯例,先上效果图 一下效果图使用三次贝塞尔曲线进行连线,代码中有直接使用直线连线的代码,可直使用. 2.查看演示请看 这里. 3 代码 html: <canvas id=&quo ...
- linux硬盘满了问题排查
关键指令: df du find step1: 如果发现硬盘满了,首先要确定一下,使用df查看硬盘使用情况 df -h step2: 从第一步结果判定满了,确定哪些文件或哪个文件占了大头,使用du指令 ...