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)的算法 看起来是 ...
随机推荐
- GET和POST面试知识点
导读:大部分APP都依赖于网络通信,对于开发者来说,基于网络通信的开发无疑是必须掌握的.HTTP通信作为目前计算机主要的通信协议,是企业面试当中必问的.对于HTTP通信的概念,本文不作说明,我将在后续 ...
- .Net使用SharpZip解压缩文件
最近,项目中使用到了上传压缩文件,文件上传到服务器后,肯定要解压,取出其中的文件才能使用,在这里做一个小结,Get这个新技能. 首先在使用NuGet管理程序在项目中添加引用ICSharpCode.Sh ...
- 初始化加载和导航时脚本执行的函数(初始化脚本执行环境)page.evaluateOnNewDocument
/** * Copyright 2017 Google Inc., PhantomJS Authors All rights reserved. * * Licensed under the Apac ...
- SqlCommand的ExecuteReader方法----转载
SqlCommand的ExecuteReader方法 原创 小道 2018-08-28 17:32:01 阅读 1353 次 评论 0 条 摘要: 用于执行查询语句,并返回一个DataReader ...
- JAVA字符串与整形、浮点类型之间的相互转换总结
1.字符串转化为整形.浮点类型 String s = "100"; //方法一 int a = Integer.parseInt(String s); Long.parseLong ...
- 7.2 Varnish 模式
- Java 推荐读物与源代码阅读
Java 推荐读物与源代码阅读 江苏无锡 缪小东 1. Java语言基础 谈到Java ...
- Lamda ForEach使用
List<User> list = new List<User>() { }, }, }, }; list.ForEach(p => Console.WriteLine( ...
- python实现PCA算法原理
PCA主成分分析法的数据主成分分析过程及python原理实现 1.对于主成分分析法,在求得第一主成分之后,如果需要求取下一个主成分,则需要将原来数据把第一主成分去掉以后再求取新的数据X’的第一主成分, ...
- 题解 nflsoj489 【六校联合训练 CSP #15】小D与随机
题目链接 考虑枚举好点的集合.此时要考虑的问题是如何填入\(1\sim n\)这些数使得恰好我们枚举到的这些点是好点,即:求出有多少种合法的填数方案. \(1\)号点一定是好点.那么除\(1\)号点外 ...