bzoj 2451 Uyuw's Concert
裸的半平面交。感觉这些东西,纯属在考代码能力啊。。
#include<cstdio>
#include<algorithm>
#include<cmath>
#define eps 1e-8
using namespace std;
int n,tot;
double ans;
struct point{double x,y;}a[];
struct line{point a,b; double angle;}l[],q[];
point operator - (point a, point b){
point t; t.x=a.x-b.x; t.y=a.y-b.y; return t;
}
long double operator * (point a, point b){
return a.x*b.y-a.y*b.x;
}
bool operator < (line a, line b){
if (a.angle==b.angle) return (b.b-a.a)*(b.a-a.a)<;
return a.angle<b.angle;
}
point intersection_point(line a, line b)
{
double k1,k2,t;
point ans;
k1=(a.b-b.a)*(b.b-b.a);
k2=(b.b-b.a)*(a.a-b.a);
t=k1/(k1+k2);
ans.x=a.b.x+(a.a.x-a.b.x)*t;
ans.y=a.b.y+(a.a.y-a.b.y)*t;
return ans;
}
bool judge(line a, line b, line t)
{
point p=intersection_point(a,b);
// printf("%lf %lf\n",a.b.x,a.b.y);
return (t.a-p)*(t.b-p)<;
}
void half_plane_intersection()
{
sort(l+,l+n+);
int top=,bottom=; tot=;
for (int i=; i<=n; i++)
if (l[i].angle!=l[i-].angle) l[++tot]=l[i];
n=tot; q[]=l[]; q[]=l[];
//for (int i=1; i<=n; i++)
// printf("%.1lf %.1lf %.1lf %.1lf\n",l[i].a.x,l[i].a.y,l[i].b.x,l[i].b.y);
for (int i=; i<=n; i++)
{
while (bottom<top && judge(q[top],q[top-],l[i])) top--;
while (bottom<top && judge(q[bottom],q[bottom+],l[i])) bottom++;
q[++top]=l[i];
}
while (bottom<top && judge(q[top],q[top-],q[bottom])) top--;
while (bottom<top && judge(q[bottom],q[bottom+],q[top])) bottom++;
q[top+]=q[bottom];
tot=;
for (int i=bottom; i<=top; i++)
a[++tot]=intersection_point(q[i],q[i+]);
}
void get_area()
{
if (tot<) return;
a[++tot]=a[];
//for (int i=1; i<=tot; i++)
// printf("%lf %lf\n",a[i].x,a[i].y); while (1);
for (int i=; i<=tot; i++)
ans+=a[i]*a[i+];
ans=fabs(ans)/;
}
int main()
{
while (~scanf("%d",&n))
{
for (int i=; i<=n; i++)
scanf("%lf%lf%lf%lf",&l[i].a.x,&l[i].a.y,&l[i].b.x,&l[i].b.y);
l[++n].a.x=; l[n].a.y=; l[n].b.x=; l[n].b.y=;
l[++n].a.x=; l[n].a.y=; l[n].b.x=; l[n].b.y=;
l[++n].a.x=; l[n].a.y=; l[n].b.x=; l[n].b.y=;
l[++n].a.x=; l[n].a.y=; l[n].b.x=; l[n].b.y=;
for (int i=; i<=n; i++)
l[i].angle=atan2((l[i].b.y-l[i].a.y),(l[i].b.x-l[i].a.x));
half_plane_intersection();
ans=; get_area();
printf("%.1lf",ans);
}
return ;
}
bzoj 2451 Uyuw's Concert的更多相关文章
- poj 2451 Uyuw's Concert (半平面交)
2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...
- poj 2451 Uyuw's Concert(半平面交)
Uyuw's Concert Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8580 Accepted: 3227 De ...
- POJ 2451 Uyuw's Concert (半平面交)
题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...
- poj 2451 Uyuw's Concert
[题目描述] Remmarguts公主成功地解决了象棋问题.作为奖励,Uyuw计划举办一场音乐会,地点是以其伟大的设计师Ihsnayish命名的巨大广场. 这个位于自由三角洲联合王国(UDF,Unit ...
- POJ 2451 Uyuw's Concert(半平面交nlgn)
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> # ...
- POJ2451 Uyuw's Concert(半平面交)
题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...
- Uyuw's Concert POJ2451
裸半平面交,以前没写过,先写一遍再说 我越来越不注意细节了,最后才发现空间稍微开小了(没有开那个零头,他又要多4条边,就WA了) const maxn=; eps=1e-7; type point=r ...
- [poj2451]Uyuw's Concert
半平面交滴裸题,但是要求nlogn,练练手 #include<iostream> #include<cstdio> #include<cmath> #include ...
- POJ2451 Uyuw's Concert (半平面交)
POJ2451 给定N个半平面 求他们的交的面积. N<=20000 首先参考 POJ1279 多边形的核 其实就是这里要求的半平面交 但是POJ1279数据较小 O(n^2)的算法 看起来是 ...
随机推荐
- 「luogu4135」作诗
「luogu4135」作诗 传送门 分块好题. 预处理出 \(f[i][j]\) 表示 \(i\) 号块到 \(j\) 号块的答案,\(num[i][k]\) 表示 \(k\) 在前 \(i\) 块的 ...
- docsify简单教程
简介 一个神奇的文档网站生成器. 简单而轻便(〜18kB压缩) 没有静态构建的HTML文件 多个主题 快速开始 建议docsify-cli全局安装,这有助于本地初始化和预览网站. npm i docs ...
- windows下pycharm连接vagrant的python环境
- MySQL实现主从复制功能
环境说明 centos7.3.MySQL5.7 前言 MySQL安装参考之前的文章https://www.jianshu.com/p/452aa99c7476有讲解. ...
- C++中%d,%s,%x,%f,%.100f,%的意思
C++中%d,%s,%x,%f,%.100f,%的意思 标准格式化输出:格式字符有d,o,x,u,c,s,f,e,g等. 格式说明:由“%”和格式字符组成,如%d.%f等. %c用来输出一个字符; % ...
- python组合数据类型和数据结构
//2019.12-071.pyhton里面组合数据类型主要有三种:集合(set).序列(字符串str.列表list and 元组tuple)和映射(字典dic)2.集合类型一般使用大括号{}来进行表 ...
- 单词「TJOI 2013」(AC自动机)
传送门 我们正常的建好Trie后求一遍fail.之后对于每一个节点,从它的fail连向它一条单项边.然后从根节点开始dfs. 记sum[i]代表从根到i号节点所代表的的字符串出现的次数,即该点的权值. ...
- 分页插件 layui.laypage 的用法
参考 layui.laypage 官方文档 https://www.layui.com/demo/laypage.html 第一步下载插件 (注意不能只引入引入 layui.css和layui.js ...
- u盘装完centos系统恢复
1.使用windows的cmd窗口,执行diskpart命令 2.执行 list disk命令,查看u盘 3.执行 select disk 2,选中u盘,注意,这里的2是我自己的显示,千万不要选错 4 ...
- Mybatis-问题总结
1.在mybatis里面注释语句的时候,一定用 <!- -需要注释的内容–>.用快捷键注释一行代码显示是/**/,但是实际执行起来报错.