题目链接:http://poj.org/problem?id=1279
Time Limit: 1000MS Memory Limit: 10000K

Description

The art galleries of the new and very futuristic building of the Center for Balkan Cooperation have the form of polygons (not necessarily convex). When a big exhibition is organized, watching over all of the pictures is a big security concern. Your task is that for a given gallery to write a program which finds the surface of the area of the floor, from which each point on the walls of the gallery is visible. On the figure 1. a map of a gallery is given in some co-ordinate system. The area wanted is shaded on the figure 2.

Input

The number of tasks T that your program have to solve will be on the first row of the input file. Input data for each task start with an integer N, 5 <= N <= 1500. Each of the next N rows of the input will contain the co-ordinates of a vertex of the polygon ? two integers that fit in 16-bit integer type, separated by a single space. Following the row with the co-ordinates of the last vertex for the task comes the line with the number of vertices for the next test and so on.

Output

For each test you must write on one line the required surface - a number with exactly two digits after the decimal point (the number should be rounded to the second digit after the decimal point).

Sample Input

1
7
0 0
4 4
4 7
9 7
13 -1
8 -6
4 -4

Sample Output

80.00

Problem solving report:

Description: 求出可以看到画廊所有地方的区域面积。
Problem solving: 首先利用半平面交求出交点,再利用这些交点求出面积。注意判断是顺时针输入还是逆时针。在POJ里面一直不知道为啥G++过不了,C++能过。。。后来才发现G++里面printf不认%lf,认%f。

Accepted Code:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1550;
const double eps = 1e-16;
typedef struct point {double x, y;
}vect;
struct line {vect p;point u, v;bool operator < (const line& s) const {return atan2(s.p.y, s.p.x) > atan2(p.y, p.x);}
};
vect operator - (const point a, const point b) {vect p;p.x = a.x - b.x;p.y = a.y - b.y;return p;
}
double dist(const point a, const point b) {return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int pnz(double x) {return x < -eps ? -1 : x > eps ? 1 : 0;
}
double Cross(const vect a, const vect b) {return a.x * b.y - a.y * b.x;
}
int Onleft(const point p, const line l) {return pnz(Cross(l.p, p - l.u));
}
point Inter(const line a, const line b) {point p;double t = Cross(b.p, a.u - b.u) / Cross(a.p, b.p);p.x = a.u.x + t * a.p.x;p.y = a.u.y + t * a.p.y;return p;
}
double Area(const point p[], int n) {double area = 0;for (int i = 1; i < n - 1; i++)area += Cross(p[i] - p[0], p[i + 1] - p[0]);return area / 2;
}
double Halfplane(line Sline[], int n) {point Spt[MAXN];int Q[MAXN] = {0};int l = 0, r = 0;sort(Sline, Sline + n);for (int i = 1; i < n; i++) {while (l < r && Onleft(Spt[r - 1], Sline[i]) < 0)r--;while (l < r && Onleft(Spt[l], Sline[i]) < 0)l++;Q[++r] = i;if (!pnz(Cross(Sline[i].p, Sline[Q[r - 1]].p))) {r--;if (Onleft(Sline[i].u, Sline[Q[r]]) > 0)Q[r] = i;}else Spt[r - 1] = Inter(Sline[i], Sline[Q[r - 1]]);}while (l < r && Onleft(Spt[r - 1], Sline[Q[l]]) < 0)r--;while (l < r && Onleft(Spt[l], Sline[Q[r]]) < 0)l++;if (r - l < 2)return 0;Spt[r] = Inter(Sline[Q[l]], Sline[Q[r]]);return Area(Spt + l, r - l + 1);
}
int main() {int n, t;point p[MAXN];line Sl[MAXN], Sline[MAXN];scanf("%d", &t);while (t--) {scanf("%d", &n);for (int i = 0; i < n; i++)scanf("%lf%lf", &p[i].x, &p[i].y);if (pnz(Area(p, n)) < 0)//利用面积的正负判断顺逆reverse(p, p + n);p[n] = p[0];for (int i = 0; i < n; i++) {Sl[i].u = p[i];Sl[i].v = p[i + 1];Sl[i].p = p[i + 1] - p[i];}printf("%.2f\n", Halfplane(Sl, n));}return 0;
}

POJ - Art Gallery(半平面交)相关推荐

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

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

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

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

  3. Feng Shui POJ - 3384 [半平面交]

    Feng Shui POJ - 3384 题意:n个顶点的凸包,放入2个半径为r的圆,可以重叠,要求面积最大,输出2个圆的圆心坐标(保留4位小数) 思路:找出圆心的可行域(内推r,求半平面交),再求核 ...

  4. POJ 3384 Feng Shui(半平面交)

    题意 : 给你一个凸多边形,让你在其中找两个圆,使得圆的覆盖面积最大. 这个题目和 poj 3525 有点类似,那个题目是一个圆,想到两者的联系,可以发现两个圆覆盖面积最大就是重叠面积最小,怎样使得重 ...

  5. POJ 1474 Video Surveillance(半平面交)

    题意:半平面交求多边形内核(我明明及的我之前是会用kuangbin第一份版平面交的,现在怎么就不会用了呢,补第二份代码) 代码: #include<cstdio> #include< ...

  6. poj 1755 Triathlon (半平面交解一元二次不等式)(切割求半平面交)

    题目链接:哆啦A梦传送门 参考链接:https://blog.csdn.net/acm_cxlove/article/details/7883370 半平面交模板 题目:铁人三项,每个人在某一项中有确 ...

  7. POJ - 3384 Feng Shui(半平面交)

    链接 Feng Shui 题意 将两个半径为 rrr 的圆放入一个多边形中,两个圆占据最大面积时圆心坐标是多少: 思路 在多边形中放圆,最大圆的圆心一定在多边形内核中: 将多边形的每条边都内推 rrr ...

  8. poj 2451 Uyuw's Concert (半平面交)

    2451 -- Uyuw's Concert 继续半平面交,这还是简单的半平面交求面积,不过输入用cin超时了一次. 代码如下: 1 #include <cstdio> 2 #includ ...

  9. POJ 1474 Video Surveillance(半平面交)

    思路:半平面交裸题,要注意是顺时针给点. #include<iostream> #include<cstdio> #include<cstring> #includ ...

  10. 半平面交练习(计算几何)

    四:半平面交 Rotating Scoreboard /*Author : lifehappy */ #include <cstdio> #include <cmath> #i ...

最新文章

  1. Android4.0 Design之UI设计易犯的错误1
  2. CentOS7.2基于LNMP搭建Wordpress
  3. 疫情之下的科技普惠:阿里云科技驱动中小企业数字化
  4. jquery this 与javascript的this
  5. 手机安卓学习 内核开发
  6. Android数据加密解密
  7. Delphi ModelMakerTools 视频教程
  8. 基于STM32的录音与播音
  9. CocosBuilder 完全攻略
  10. Java 案例七 超市管理系统(商品清单,商品添加,商品删除,修改库存)
  11. android系统wifi控制风扇,可手机APP控制的机箱风扇,光污染新玩法
  12. 【学习笔记】噬菌体学
  13. Sched: RT throttling activated
  14. 服务器多个cpu的作用,服务器多核CPU是什么?多核CPU有什么用?
  15. java代码运行的三个步骤,22年最新
  16. Fruit 有上下限的母函数
  17. 三阶魔方大中小魔公式_三阶魔方还原公式
  18. Pr 视频效果:视频
  19. 选购地磁传感器应避免哪些坑
  20. c++实验2:6-4 求余弦函数近似值

热门文章

  1. qq飞车手游微信24区服务器,QQ飞车手游手游开服表_QQ飞车手游手游开服时间表_新服新区预告_第一手游网...
  2. 人体一机竞技格斗机器人_在格斗机器人比赛中,如何判断输赢?
  3. 8大排序算法总结-Python
  4. python微信群发助手在哪_python 微信群发_Python-Pyqt5编写微信群发软件
  5. 写日报、写日报,每天都要写,写工作日报到底有什么意义?
  6. 涂师傅手机数据恢复官方版
  7. 陈彤离职,新浪在门户竞争中将继续被边缘化
  8. 地方棋牌游戏里的家乡情结
  9. 小屏幕android手机,小尺寸、小屏幕的安卓手机有哪些
  10. 软件工程—团队作业1(三人行)