【POJ】1279 Art Gallery
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的更多相关文章
- poj 1279 -- Art Gallery (半平面交)
鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- poj 1279 Art Gallery - 求多边形核的面积
/* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...
- poj 1279 Art Gallery (Half Plane Intersection)
1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...
- 【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, ...
- 【POJ】1067 取石子游戏(博弈论)
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- 【POJ】【2068】Art Gallery
计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...
- 【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$都是偶数啦~ ...
- 【POJ】【2104】区间第K大
可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...
- 【POJ】1222 EXTENDED LIGHTS OUT
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...
随机推荐
- Java获取、删除文件和目录
package javatest; import java.io.File; import java.util.ArrayList; import java.util.regex.Pattern; c ...
- ssh连接慢的问题的解决?
<1>群中同学遇到的问题,我之前在uuwatch也遇到了同样的问题? 问个问题师兄们 突然之间 公司服务器连接很慢 连一个shell需要10几秒钟 服务器就在公司全是内网服务器, 我也不知 ...
- TCP/IP WebSocket MQTT
http://www.cnblogs.com/shanyou/p/4085802.html TCP/IP, WebSocket 和 MQTT
- 多表利用DIH批量导入数据并建立索引注意事项
如果希望同时对多个表进行全文检索,那我们该如何处理呢?利用DIH导入数据并建立索引时.schema.xml中配置了uniqueKey为id <uniqueKey>id</unique ...
- 【转】maven仓库快速镜像
本文转自:http://blog.csdn.net/zuoluoboy/article/details/20007819 国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的mav ...
- Windbg程序调试--转载
WinDbg是微软发布的一款相当优秀的源码级(source-level)调试工具,可以用于Kernel模式调试和用户模式调试,还可以调试Dump文件. WinDbg是微软很重要的诊断调试工具: 可以查 ...
- hdu 1879 继续畅通工程 解题报告
题目链接:http://code.hdu.edu.cn/showproblem.php?pid=1879 这条题目我的做法与解决Constructing Roads的解法是相同的. 0 表示没有连通: ...
- android 输入法出现挤压屏幕、android输入键盘覆盖了屏幕控件的解决办法
如果希望输入法键盘弹出时不自动向上挤压activity,在Manifest清单文件中对应的activty中设置属性android:windowSoftInputMode="adjustPan ...
- eclipse + Android Studio 集成 Genymotion 模拟器
Genymotion 官网 -- android 模拟器https://www.genymotion.com 虚拟机下载安装目录C:\Users\xxx\AppData\Local\Genymobil ...
- 从C# 到 OC
字符串 声明: C#: string name = “lwme.cnblogs.com”; Objective-C: NSString *name = @”lwme.cnblogs.com”; 字符串 ...