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. 添加本地 yum源

    添加本地 yum源 yum-updatesd.conf yum的主配置文件   [root@zhou ~]# cd /etc/yum.repos.d/ [root@zhou yum.repos.d]# ...

  2. 归档备份被删,GoldenGate无法抽取数据

    发生错误如下,源端EXTRACT进程异常中止,查看日志,发现如下错误. 2014-07-23 01:32:13  ERROR   OGG-00446  Oracle GoldenGate Captur ...

  3. 运维派 企业面试题2 创建10个 "十个随机字母_test.html" 文件

    Linux运维必会的实战编程笔试题(19题) 企业面试题2: 使用for循环在/tmp/www目录下通过随机小写10个字母加固定字符串test批量创建10个html文件,名称例如为: --[root@ ...

  4. windows server 2012安装.NET3.5安装提示需要指定源路径 安装.net3.5提示安装不成功,提示需要指定源路径。

    安装.net3.5提示安装不成功,提示需要指定源路径.   正确的操作步骤: 1.需要下载windows server 2012操作系统盘.用解压工具解压出来.       2012操作系统下载地址: ...

  5. python读取word文档

    周末需要做一个统计word文档字数的问题,刚开始以为很简单,因为之前做过excel表格相关的任务,所以认为利用扩展模块应该比较简单. 通过搜索,确实搜到了一个python操作word的模块,pytho ...

  6. Python学习笔记(5)--数据结构之字典dict

    字典(dict) 定义:键值对集合 初始化:{}, {'1' : 'abc', '2' : 'def'} 1.增加:单个数据直接赋值  update(dict2) ---把dict2的元素加入到dic ...

  7. Xwiki平台Windows搭建(Tomcat7 + XWiki6.2 + MySQL5.5)

    背景介绍 国内xwiki安装使用资料较少,根据自己使用xwiki经验,总结出来,供参考,同时希望感兴趣的朋友能够一起讨论,XWiki是一个强大的Java开源的Wiki引擎. 它支持一些受欢迎的特性如: ...

  8. js使用offsetHeight获取div高度为0的问题

    今晚试了好久没弄出来,后来获取子一层的div就能获取到高度了 我的情况是这样的:我在最外面写一个<div id="mainBody">,  里面写bootstrap的d ...

  9. ArcGIS api for javascript——查询没有地图的数据

    描述 本例展示了用户能够从没有显示服务的地图服务查询数据.大部分地图服务包含属性信息的数据集,数据集能够被查询并显示在一个简单的列或表格里. 本例按提供的州名称查询USA人口普查数据,然后显示关于州的 ...

  10. 习题(3-3) 计算(a+b)*c的值

    题目 - 习题(3-3) 计算(a+b)*c的值   来源 计算概论B 2010 描写叙述 计算表达式(a+b)*c的值,当中a, b, c均为整数,且a,b,c的值介于-10000和10000之间( ...