BZOJ-2618 [CQOI2006]凸多边形
半平面交模版题。。
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <algorithm>
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define clr(x, c) memset(x, c, sizeof(x))
#define maxn 1000
//#define double long double
#define linf 1e15
using namespace std;
typedef long long ll;
inline int read()
{
int x=0, f=1; char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();
return x*f;
}
struct P{double x, y;} p[maxn];
P operator - (P a, P b){return (P){a.x-b.x, a.y-b.y};}
double operator * (P a, P b){return a.x*b.y-b.x*a.y;}
struct line{P a, b; double ang;} l[maxn], a[maxn], q[maxn];
bool operator < (line a, line b){if (a.ang==b.ang) return (a.b-a.a)*(b.a-a.a)>0; return a.ang<b.ang;} inline P inter(line a, line b)
{
double k1=(b.b-a.a)*(a.b-a.a), k2=(a.b-a.a)*(b.a-a.a), t=k2/(k1+k2);
return (P){b.a.x+t*(b.b.x-b.a.x), b.a.y+t*(b.b.y-b.a.y)};
}
inline bool jud(line x, line y, line v){return (inter(x, y)-v.a)*(v.b-v.a)>0;}
int n, m, cnt;
int main()
{
n=read();
rep(i, 1, n)
{
int k=read();
rep(j, 1, k) p[j].x=read(), p[j].y=read(); p[k+1]=p[1];
rep(j, 1, k) l[++m].a=p[j], l[m].b=p[j+1];
}
rep(i, 1, m) l[i].ang=atan2(l[i].b.y-l[i].a.y, l[i].b.x-l[i].a.x);
sort(l+1, l+1+m);
rep(i, 1, m)
a[l[i].ang!=a[cnt].ang ? ++cnt : cnt]=l[i];
int L=1, R=0; q[++R]=a[1]; q[++R]=a[2];
rep(i, 3, cnt)
{
while (L<R && jud(q[R-1], q[R], a[i])) R--;
while (L<R && jud(q[L+1], q[L], a[i])) L++;
q[++R]=a[i];
}
while (L<R && jud(q[R-1], q[R], q[L])) R--;
while (L<R && jud(q[L+1], q[L], q[R])) L++;
if (R-L<2) {puts("0.000"); return 0;}
cnt=0; q[R+1]=q[L]; rep(i, L, R) p[++cnt]=inter(q[i], q[i+1]);
double ans=0;
rep(i, 1, cnt-1) ans+=p[i].x*p[i+1].y; ans+=p[cnt].x*p[1].y;
rep(i, 2, cnt) ans-=p[i].x*p[i-1].y; ans-=p[1].x*p[cnt].y;
if (ans<0) ans*=-1;
printf("%.3lf", ans/2);
return 0;
}
BZOJ-2618 [CQOI2006]凸多边形的更多相关文章
- bzoj 2618: [Cqoi2006]凸多边形 [半平面交]
2618: [Cqoi2006]凸多边形 半平面交 注意一开始多边形边界不要太大... #include <iostream> #include <cstdio> #inclu ...
- 2018.07.04 BZOJ 2618 Cqoi2006凸多边形(半平面交)
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MB Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n ...
- ●BZOJ 2618 [Cqoi2006]凸多边形
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2618 题解: 计算几何,半平面交. 给出一些凸包,求面积交. 把所有边都取出来,直接办平面交 ...
- 【BZOJ 2618】 2618: [Cqoi2006]凸多边形 (半平面交)
2618: [Cqoi2006]凸多边形 Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. Input 第一 ...
- bzoj 2618 2618: [Cqoi2006]凸多边形(半平面交)
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 656 Solved: 340[Submit][Status] ...
- 【BZOJ2618】[CQOI2006]凸多边形(半平面交)
[BZOJ2618][CQOI2006]凸多边形(半平面交) 题面 BZOJ 洛谷 题解 这个东西就是要求凸多边形的边所形成的半平面交. 那么就是一个半平面交模板题了. 这里写的是平方的做法. #in ...
- 洛谷 P4196 [CQOI2006]凸多边形 (半平面交)
题目链接:P4196 [CQOI2006]凸多边形 题意 给定 \(n\) 个凸多边形,求它们相交的面积. 思路 半平面交 半平面交的模板题. 代码 #include <bits/stdc++. ...
- BZOJ - 2618 凸多边形 (半平面交)
题意:求n个凸多边形的交面积. 半平面交模板题. #include<bits/stdc++.h> using namespace std; typedef long long ll; ty ...
- bzoj2618: [Cqoi2006]凸多边形
Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. Input 第一行有一个整数n,表示凸多边形的个数,以下依 ...
- BZOJ 2222: [Cqoi2006]猜数游戏【神奇的做法,傻逼题,猜结论】
2222: [Cqoi2006]猜数游戏 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 604 Solved: 260[Submit][Status ...
随机推荐
- 2017.12.25 Java中面向对象思想的深刻理解
今日内容介绍 1.面向对象思想 2.类与对象的关系 3.局部变量和成员变量的关系 4.封装思想 5.private,this关键字 6.随机点名器 01面向对象和面向过程的思想 * A: 面向过程与面 ...
- python_12_continue
for i in range(9): if i<3: print("loop",i) else: continue#跳出本次循环,继续到下一循环 print('hehe... ...
- JoinQuant策略代码示例
总体回测前 ''' ================================================================================ 总体回测前 === ...
- hadoop + ssh 配置
1.输入 2.解决上述问题 3. 4.去掉登陆密码 5.不用密码登陆
- kindeditor 上传图片失败问题总结
1.近段时间一直在处理kindeditor上传图片失败的问题,前期一直以为是前端的问题,利用谷歌控制台,打断点,修改方法,一直都找不到解决方案,直到查看服务器配置,才发现: WEB 1号服务器 /da ...
- C/C++程序基础 (七)继承和多态
多态 编译时多态:重载 运行时多态:虚函数.根据运行时的类别获取正确的虚指针,从而定位正确的虚函数. 虚函数 虚函数指针:指向虚函数表.多重继承则含有多个基类的虚函数指针. 虚函数表:函数指针集合.普 ...
- Swoole 4.1.0 正式版发布,支持原生 Redis/PDO/MySQLi 协程化
重大新特性 支持 Redis/PDO/MySQLi 从4.1.0版本开始支持了对PHP原生Redis.PDO.MySQLi协程化的支持. 可使用Swoole\Runtime::enableCorotu ...
- 分享 php array_column 函数 无法在低版本支持的 修改
function i_array_column($input, $columnKey, $indexKey=null){ if(!function_exists('array_column')){ $ ...
- django-simple-captcha 验证码干扰线随机点位
CAPTCHA_NOISE_FUNCTIONS = ( 'captcha.helpers.noise_null',# 设置样式 'captcha.helpers.noise_arcs',# 设置干扰线 ...
- Paul Zindel【保罗·金代尔】
Paul Zindel Paul Zindel's death on March 27, 2003 ended the brilliant life of a famous write. 2003年3 ...