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 ...
随机推荐
- 基于GMap.NET地图下载器的开发和研究
基于GMap.NET地图下载器的开发和研究 软件下载地址:https://pan.baidu.com/s/1ay0aOm3fiZ35vlfD8kFYFw 1.地图浏览功能 可以浏览谷歌地图.百度.ar ...
- 1503: [NOI2004]郁闷的出纳员
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 13723 Solved: 4989[Submit][Status][Discuss] Descripti ...
- 2D和3D效果
<style type="text/css"> #div1{ width: 200px; height: 200px; background-color:#aaa; c ...
- Thinkphp5封装上传图片
<?php namespace app\api\controller; use think\Controller; use think\Db; class Plus extends Base{ ...
- STM32的四种输出模式(转载)
1.普通推挽输出(GPIO_Mode_Out_PP): 使用场合:一般用在0V和3.3V的场合.线路经过两个P_MOS 和N_MOS 管,负责上拉和下拉电流. 使用方法:直接使用 输出电平 ...
- 2、大O表示法
一.大O表示法 大O表示法不是一种算法.它是用来表示一个算法解决问题的速度的快慢.一般我们描述一件事情完成的快慢是用时间描述的,比如说我完成一道计算题用了多少分钟.但算法的运算是很难用准确的时间来描述 ...
- 命令执行sql
从外网把数据库用导出脚本的方式导出来了,280M的样子,导是导出来了,但是在本机执行sql脚本的时候,直接就是out of memory,之前执行60M的脚本没出过这问题,直接双击打开.sql脚本文件 ...
- MapReduce实现单词统计
开发工具:IDEA mapreduce实现思路: Map阶段: a) 从HDFS的源数据文件中逐行读取数据 b) 将每一行数据切分出单词 c) 为每一个单词构造一个键值对(单词,1) d) 将键值对 ...
- 【NopCommerce 3.1】asp.net mvc 利用jQuery from.js上传用户头像
纯代码不解释. 在CusotmerControllers中添加上传方法 /// <summary> /// ajax上传用户头像 /// </summary> /// < ...
- 【IPv6】ISATAP隧道技术详解
一.基本概念 ISATAP(Intra-SiteAutomatic Tunnel Addressing Protocol) ISATAP是一种非常容易部署和使用的IPv6过渡机制.在 ...