http://poj.org/problem?id=1279

顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题

这里的半平面交是O(n^2)的算法...比较逗比...暴力对每条线段做半平面交...要注意的地方写在注释里了...顺序写反了卡了我好久

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN 10005
#define MOD (int)1e9+7
#define PI acos(-1.0)
#define INF ((1LL)<<50)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define LLINE cout<<"------------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// int gcd(int a,int b){ return b?gcd(b,a%b):a; }
// int lcm(int a,int b){ return a*b/gcd(a,b); } /********************* F ************************/
struct POINT{
double x,y;
POINT(double _x = , double _y = ):x(_x),y(_y){}
}p[MAXN],q[MAXN],t[MAXN];
int n;
struct LINE{
double a,b,c;
POINT A,B;
LINE(POINT _a, POINT _b):A(_a),B(_b){
a=B.y-A.y;
b=A.x-B.x;
c=B.x*A.y-A.x*B.y;
}
};
double multiply(POINT sp,POINT ep,POINT op){ //叉积 左+ 右-
return (sp.x-op.x) * (ep.y-op.y) - (ep.x-op.x) * (sp.y-op.y);
}
POINT Intersection(LINE a,LINE b){ //直线交点
double u = fabs(b.A.x * a.a + b.A.y * a.b + a.c);
double v = fabs(b.B.x * a.a + b.B.y * a.b + a.c);
POINT t;
t.x = (b.A.x * v + b.B.x * u) / (u + v);
t.y = (b.A.y * v + b.B.y * u) / (u + v);
return t;
}
double Triangle_area(POINT a,POINT b,POINT c){ //求三角形面积(带符号)
return multiply(a,b,c)/;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("outm.txt","w",stdout);
int ct = ;
int T;
cin>>T;
while(T--){
cin>>n;
for(int i = ; i < n ; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
//暴力对每一个向量作半平面交 ...即将右侧的点和与其他直线的交点加入集合
for(int i = ; i < n ; i++) q[i] = p[i];
int cnt = n;
for(int i = ; i < n ; i++){
int c = ;
for(int j = ; j < cnt ; j++){
//点在右侧
if(multiply(p[i],p[(i+)%n],q[j]) <= EPS) {
t[c++] = q[j];
}else { //点在左侧,但是前后线段和该直线有交点
//这个顺序不要写反,否则不是顺时针会WA
if(multiply(p[i],p[(i+)%n],q[(j-+cnt)%cnt]) < -EPS){
t[c++] = Intersection(LINE(p[i],p[(i+)%n]) , LINE(q[j],q[(j-+cnt)%cnt]));
}
if(multiply(p[i],p[(i+)%n],q[(j+)%cnt]) < -EPS){
t[c++] = Intersection(LINE(p[i],p[(i+)%n]) , LINE(q[j],q[(j+)%cnt]));
}
}
}
for(int j = ; j < c ; j++) q[j] = t[j];
cnt = c;
}
double area = ;
for(int i = ; i < cnt ; i++){
area += Triangle_area(POINT(,),q[i],q[(i+)%cnt]);
}
area = fabs(area);
printf("%.2lf\n",area);
}
return ;
}

POJ 1279 Art Gallery 半平面交/多边形求核的更多相关文章

  1. POJ 1279 Art Gallery 半平面交 多边形的核

    题意:求多边形的核的面积 套模板即可 #include <iostream> #include <cstdio> #include <cmath> #define ...

  2. POJ 1279 Art Gallery 半平面交求多边形核

    第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内 ...

  3. POJ 1279 Art Gallery(半平面交)

    题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...

  4. poj 1279 Art Gallery - 求多边形核的面积

    /* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...

  5. poj 1279 -- Art Gallery (半平面交)

    鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  6. poj 1279 Art Gallery (Half Plane Intersection)

    1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...

  7. POJ 1279 Art Gallery【半平面交】(求多边形的核)(模板题)

    <题目链接> 题目大意: 按顺时针顺序给出一个N边形,求N边形的核的面积. (多边形的核:它是平面简单多边形的核是该多边形内部的一个点集该点集中任意一点与多边形边界上一点的连线都处于这个多 ...

  8. POJ 1279 Art Gallery(半平面交求多边形核的面积)

    题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...

  9. [POJ]1279: Art Gallery

    题目大意:有一个N边形展馆,问展馆内有多少地方可以看到所有墙壁.(N<=1500) 思路:模板题,半平面交求出多边形的核后计算核的面积. #include<cstdio> #incl ...

随机推荐

  1. UI Framework-1: Aura Client API

    Client API The Aura Client API is an API Aura uses to communicate with the client application using ...

  2. Unix版权史

    原文出处: 阮一峰    这几天,我在读<Unix编程艺术>. 书中介绍了Unix的发展历史.我发现,这是一个很好的例子,说明现行版权制度具有阻碍社会发展的负面作用. 2. Unix诞生于 ...

  3. HDU-1032 The 3n+1 problem 模拟问题(水题)

    题目链接:https://cn.vjudge.net/problem/HDU-1032 水题 代码 #include <cstdio> #include <algorithm> ...

  4. python第三次作业——叶耀宗

    作业1 import random#引入随机数模块xing=["小白","小黄","小王","小陈","小绿& ...

  5. [Code+#4]最短路 (最短路)

    [Code+#4]最短路 题目背景 在北纬 91° ,有一个神奇的国度,叫做企鹅国.这里的企鹅也有自己发达的文明,称为企鹅文明.因为企鹅只有黑白两种颜色,所以他们的数学也是以二进制为基础发展的. 比如 ...

  6. linux 下查看二进制文件

    查看二进制有以下几种方法: 方法一:hexdump apt-get install libdata-hexdumper-perl 安装好之后就可以直接hexdump your_binary_file ...

  7. Eclipse StartExplorer插件

    http://www.cnblogs.com/wuxiang/p/5489961.html

  8. hadoop(八) - sqoop安装与使用

    一. sqoop安装: 安装在一台节点上就能够了. 1. 使用winscp上传sqoop 2. 安装和配置 加入sqoop到环境变量 将数据库连接驱动mysql-connector-5.1.8.jar ...

  9. 在kettle中实现数据验证和检查

    在kettle中实现数据验证和检查 在ETL项目,输入数据通常不能保证一致性.在kettle中有一些步骤能够实现数据验证或检查.验证步骤能够在一些计算的基础上验证行货字段:过滤步骤实现数据过滤:jav ...

  10. VGA接口时序约束

    SF-VGA模块板载VGA显示器DA转换驱动芯片AVD7123,FPGA通过OUPLLN连接器驱动ADV7123芯片产生供给VGA显示器的色彩以及同步信号.SF-CY3核心模块与SF-VGA子模块连接 ...