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

题意:给一个n个点的多边形,n<=1500,求在多边形内能看到所有多边形上的点的面积。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } const double eps=1e-6;
const int N=1515;
int dcmp(double x) { return abs(x)<eps?0:(x<0?-1:1); }
struct iP { double x, y; iP(double _x=0, double _y=0) : x(_x), y(_y) {} };
typedef iP iV;
iV operator - (iP a, iP b) { return iV(a.x-b.x, a.y-b.y); }
iP operator + (iP a, iV b) { return iP(a.x+b.x, a.y+b.y); }
iV operator * (iP a, double d) { return iV(a.x*d, a.y*d); }
double cross(iV a, iV b) { return a.x*b.y-a.y*b.x; }
double angle(iV &a) { return atan2(a.y, a.x); } struct iL {
iV v; iP p;
double ang;
void set(iP a, iP b) { p=a; v=b-a; ang=angle(v); }
bool operator<(const iL &b) const { return ang<b.ang; }
};
iP LLi(iL &a, iL &b) {
static iV u;
static double t;
u=a.p-b.p;
t=cross(b.v, u)/cross(a.v, b.v);
return a.p+a.v*t;
}
bool onL(iP &a, iL &l) { return dcmp(cross(l.v, a-l.p))>0; }
bool half(iL *line, int n, iP *s, int &cnt) {
static iL a[N], q[N];
static iP b[N];
static int front, tail;
memcpy(a, line, sizeof(iL)*(n+1));
sort(a+1, a+1+n);
q[front=tail=0]=a[1];
for1(i, 2, n) {
while(front!=tail && !onL(b[tail-1], a[i])) --tail;
while(front!=tail && !onL(b[front], a[i])) ++front;
q[++tail]=a[i];
if(dcmp(cross(q[tail-1].v, q[tail].v))==0) {
--tail;
if(onL(a[i].p, q[tail])) q[tail]=a[i];
}
if(front!=tail) b[tail-1]=LLi(q[tail], q[tail-1]);
}
while(front!=tail && !onL(b[tail-1], q[front])) --tail;
if(tail-front<=1) return 0;
cnt=0;
b[tail]=LLi(q[tail], q[front]);
for1(i, front, tail) s[++cnt]=b[i];
return 1;
} iL line[N];
iP a[N], b[N];
int ln, n, num, flag;
void add(iP a, iP b) { ++ln; line[ln].set(a, b); } void clr() { num=ln=0; }
void readin() { read(n); for1(i, 1, n) scanf("%lf%lf", &a[i].x, &a[i].y); }
void build() {
a[n+1]=a[1];
for1(i, 1, n) add(a[i+1], a[i]);
}
void work() { flag=half(line, ln, b, num); }
void getans() {
if(!flag) { puts("0.00"); return; }
double ans=0;
b[num+1]=b[1];
for1(i, 1, num) ans+=b[i].x*b[i+1].y-b[i].y*b[i+1].x;
printf("%.2f\n", ans/2);
} int main() {
int ta=getint();
while(ta--) {
clr();
readin();
build();
work();
getans();
}
return 0;
}

  


裸的半平面交.................

【POJ】1279 Art Gallery的更多相关文章

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

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

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

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

  3. poj 1279 Art Gallery (Half Plane Intersection)

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

  4. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

  5. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

  6. 【POJ】【2068】Art Gallery

    计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...

  7. 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉

    DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $  当然这里的$i$和$k$都是偶数啦~ ...

  8. 【POJ】【2104】区间第K大

    可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...

  9. 【POJ】1222 EXTENDED LIGHTS OUT

    [算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...

随机推荐

  1. discuz 帖子模块用到的表及自动发帖函数

    最近在做一个discuz的插件,由于需要程序自动生成并调用discuz已经存在插件的帖子.然而这就相当于自动发帖的功能了.网上找了一下,大部分都是通过curl模拟登陆,模拟发帖的,这显然不满足我的要求 ...

  2. mysql导入和导出数据

    Linux下如何单个库进行导入和备份操作 1.将数据导入数据库mysql -u账号 -p密码 数据库<sql脚本 mysql -uroot -proot test</home/upload ...

  3. Java for LeetCode 035 Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  4. fedora yum 使用代理的方法

    配置yum: 编辑/etc/yum.conf添加下列一行: proxy=http://domain/user:passwd@<proxy ip>:80 <proxy ip>:代 ...

  5. Android之Intent深入

    Android中的意图包含多种用法,本文主要包括以下内容 显式意图 隐匿意图 要求结果回传的意图 显式意图 :必须指定要激活的组件的完整包名和类名 (应用程序之间耦合在一起) 一般激活自己应用的组件的 ...

  6. 配置无线网络的时候会提示“Enter Password for Default Keyring to Unlock”

    密钥管理软件Seahorse有关,这个时候我们打开c配置一下就可以解决. 命令行下运行seahorse或依次点击菜单“应用程序→附件→密码和加密密钥”, 在login一行中右键选择更改密码,然后什么都 ...

  7. poj 2923 状压dp+01背包

    好牛b的思路 题意:一系列物品,用二辆车运送,求运送完所需的最小次数,两辆车必须一起走 解法为状态压缩DP+背包,本题的解题思路是先枚举选择若干个时的状态,总状态量为1<<n,判断这些状态 ...

  8. ava中Class.forName的作用浅谈

    转自:http://www.jb51.net/article/42648.htm Class.forName(xxx.xx.xx) 返回的是一个类 一.首先你要明白在java里面任何class都要装载 ...

  9. POJ1236 - Network of Schools tarjan

                                                     Network of Schools Time Limit: 1000MS   Memory Limi ...

  10. 电赛总结(二)——AD芯片总结之音频处理芯片ADC8009

    一.特性参数 1.专门用来用音频处理的AD芯片 2.内部固定好8K的采样速率 3.8位AD芯片 二.内部结构图 三.芯片管脚图 四.管脚功能说明 管脚名称 功能 IN0~IN7 数据输入端 ABC 数 ...