poj2451Uyuw's Concert(半平面交)
逆时针给出线段,如果模板是顺时针的修改下系数的符号进行平面交即可。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 20100
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int m;
int cCnt,curCnt;
struct point
{
double x,y;
point(double x=,double y = ):x(x),y(y) {}
};
point points[N],p[N],q[N];
void getline(point x,point y,double &a,double &b,double &c)
{
a = x.y - y.y;
b = y.x - x.x;
c = x.x * y.y-y.x * x.y;
}
void initial()
{
for(int i = ; i <= m; ++i)p[i] = points[i];
p[m+] = p[];
p[] = p[m];
cCnt = m;
}
point intersect(point x,point y,double a,double b,double c)
{
double u = fabs(a * x.x + b * x.y + c);
double v = fabs(a * y.x + b * y.y + c);
point pt;
pt.x=(x.x * v + y.x * u) / (u + v);
pt.y=(x.y * v + y.y * u) / (u + v);
return pt;
}
void cut(double a,double b ,double c)
{
curCnt = ;
for(int i = ; i <= cCnt; ++i)
{
if(a*p[i].x + b*p[i].y + c >= )q[++curCnt] = p[i];
else
{
if(a*p[i-].x + b*p[i-].y + c > )
q[++curCnt] = intersect(p[i],p[i-],a,b,c);
if(a*p[i+].x + b*p[i+].y + c > )
q[++curCnt] = intersect(p[i],p[i+],a,b,c);
}
}
for(int i = ; i <= curCnt; ++i)p[i] = q[i];
p[curCnt+] = q[];
p[] = p[curCnt];
cCnt = curCnt;
}
void solve()
{
double area = ;
for(int i = ; i <= cCnt; ++i)
area += p[i].x * p[i + ].y - p[i + ].x * p[i].y;
area = fabs(area / 2.0);
printf("%.1f\n",area); }
void GuiZhengHua()
{
//规整化方向,逆时针变顺时针,顺时针变逆时针
for(int i = ; i < (m+)/; i ++)
swap(points[i], points[m-i]);
}
int main()
{
points[] = point(,);
points[] = point(,);
points[] = point(,);
points[] = point(,);
points[] = p[];
int n,i;
while(scanf("%d",&n)!=EOF)
{
m = ;
initial();
for(i = ; i <= ; ++i)
{
double a,b,c;
getline(points[i],points[i+],a,b,c);
cut(a,b,c);
}
for(i = ; i <= *n ; i+=)
{
point p1,p2;
scanf("%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y);
double a,b,c;
getline(p1,p2,a,b,c);
cut(a,b,c);
} // m = 2*n+4;
//GuiZhengHua();
//points[m+1] = points[1];
solve();
}
return ;
}
poj2451Uyuw's Concert(半平面交)的更多相关文章
- POJ 2451 Uyuw's Concert (半平面交)
题目链接:POJ 2451 Problem Description Prince Remmarguts solved the CHESS puzzle successfully. As an awar ...
- POJ2451 Uyuw's Concert(半平面交)
题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...
- poj 2451 Uyuw's Concert (半平面交)
2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: #include <cstdio> #include &l ...
- POJ2451 Uyuw's Concert (半平面交)
POJ2451 给定N个半平面 求他们的交的面积. N<=20000 首先参考 POJ1279 多边形的核 其实就是这里要求的半平面交 但是POJ1279数据较小 O(n^2)的算法 看起来是 ...
- 半平面交总结and模板
博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/40859973 这两天刷了POJ上几道半平面交,对半平面交有了初步的体会,感觉半 ...
- 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)
按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...
- 【BZOJ-2618】凸多边形 计算几何 + 半平面交 + 增量法 + 三角剖分
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 959 Solved: 489[Submit][Status] ...
- 【CSU1812】三角形和矩形 【半平面交】
检验半平面交的板子. #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define gg p ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
随机推荐
- JavaEE基础(十一)/Eclipse介绍
1.Java开发工具(常见开发工具介绍) A:操作系统自带的记事本软件 B:高级记事本软件 C:集成开发环境 IDE (Integrated Development Environment) D:Ec ...
- ectouch第十讲 之ecshop中 dwt, lbi 文件详解
原文:http://www.yunmoban.cn/article-241.html Ecshop包括的文件夹有admin.api.cert.data.images.includes.js. lang ...
- vi复制文字
可以对文字使用标记,在光标处使用 ma 将该行标记为a,可用`a (反引号)定位到该标记a位置,用'a (单引号)定位到该行行首. d$删除光标位置到行尾,y$取光标位置到行尾.d和y也可配合标记使用 ...
- northwind数据库
① Categories: 种类表相应字段:CategoryID :类型ID:CategoryName:类型名;Description:类型说明;Picture:产品样本 ② CustomerCust ...
- (翻译)理解Java当中的回调机制
原文地址:http://cleancodedevelopment-qualityseal.blogspot.com/2012/10/understanding-callbacks-with-java. ...
- 水流雨渍shader
战神斯巴达之魂的雨渍做的很逼真,尝试了下,似乎是差不多了,整体欠缺不少 普通平面: 环形流动: 河流: shader实现,3层加上一个偏移层 圆形的雨渍流动和河流要重新展一下UV
- TCP数据流稳定性--TCP分片,重组及乱序
http://www.cnblogs.com/derekchen/archive/2009/07/15/1524415.html 1.IP分片的情况.IP软件包有一个[分片]和[重组]模块,一个IP数 ...
- JAVA基础知识之Collections工具类
排序操作 Collections提供以下方法对List进行排序操作 void reverse(List list):反转 void shuffle(List list),随机排序 void sort( ...
- UVa(247),Floyd做传递闭包
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 数据库 使用DML语句更改数据
使用DML语句更改数据 添加新数据: 插入单行语句: Insert into 表名(列名)values(‘值’); 插入多行:insert into 表名(列名,…..) Values(‘值’,’值’ ...