【POJ】【2068】Art Gallery
计算几何/半平面交
裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621
然而代码我是抄的proverbs的……
大体思路是这样的:(一个增量算法)
维护一个当前的半平面交的点集,每次用一条直线去cut它:
依次枚举“凸包”上的点,点在直线左边则保留下来了,否则就丢掉=。=
同时判一下如果“凸包”上连续的两个点分别在直线两侧,就加入这条“凸包”上的线段与直线的交点= =
然后新点集get!
最后求个面积>_>
有个trick是如果给的顺序是顺时针,需要反转成逆时针(用算多边形面积的方法就可以判断,如果是逆时针,面积为正)
- Source Code
- Problem: User: sdfzyhy
- Memory: 720K Time: 32MS
- Language: G++ Result: Accepted
- Source Code
- //POJ 1279
- #include<cmath>
- #include<vector>
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<iostream>
- #include<algorithm>
- #define rep(i,n) for(int i=0;i<n;++i)
- #define F(i,j,n) for(int i=j;i<=n;++i)
- #define D(i,j,n) for(int i=j;i>=n;--i)
- #define pb push_back
- using namespace std;
- inline int getint(){
- int v=,sign=; char ch=getchar();
- while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
- while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
- return v*sign;
- }
- const int N=1e5+;
- const double INF=1e9;
- typedef long long LL;
- /******************tamplate*********************/
- const double eps=1e-;
- int dcmp(double x){return x>eps ? : x<-eps ? - : ;}
- struct Poi{
- double x,y;
- Poi(){}
- Poi(double x,double y):x(x),y(y){}
- void read(){scanf("%lf%lf",&x,&y);}
- }p[N],tp[N],s[N],o;
- typedef Poi Vec;
- Vec operator - (const Poi&a,const Poi &b){return Vec(a.x-b.x,a.y-b.y);}
- int n;
- double Cross(const Vec &a,const Vec &b){return a.x*b.y-a.y*b.x;}
- double getarea(Poi *p,int n){
- double ans=0.0;
- F(i,,n) ans+=Cross(p[i]-o,p[i+]-o);
- return ans*0.5;
- }
- Poi getpoint(const Poi &a,const Poi &b,const Poi &c,const Poi &d){
- Poi ans,tmp=b-a;
- double k1=Cross(d-a,c-a),k2=Cross(c-b,d-b);
- ans.x=a.x+tmp.x*k1/(k1+k2);
- ans.y=a.y+tmp.y*k1/(k1+k2);
- return ans;
- }
- void init(){
- n=getint();
- F(i,,n) p[i].read();
- p[n+]=p[];
- }
- void Change(){
- F(i,,n>>) swap(p[i],p[n-i+]);
- p[n+]=p[];
- }
- void getcut(){
- tp[]=tp[]=Poi(-INF,-INF);
- tp[]=Poi(INF,-INF);
- tp[]=Poi(INF,INF);
- tp[]=Poi(-INF,INF);
- int num=,size=;
- F(i,,n){
- size=;
- F(j,,num){
- if (dcmp(Cross(p[i+]-p[i],tp[j]-p[i]))>=)
- s[++size]=tp[j];
- if (dcmp(Cross(p[i+]-p[i],tp[j]-p[i]) *
- Cross(p[i+]-p[i],tp[j+]-p[i]))<)
- s[++size]=getpoint(p[i],p[i+],tp[j],tp[j+]);
- }
- s[size+]=s[];
- F(j,,size+) tp[j]=s[j];
- num=size;
- }
- n=num;
- }
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("1279.in","r",stdin);
- freopen("1279.out","w",stdout);
- #endif
- int T=getint();
- while(T--){
- init();
- if (dcmp(getarea(p,n))<=) Change();
- getcut();
- printf("%.2f\n",fabs(getarea(s,n)));
- }
- return ;
- }
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5805 | Accepted: 2455 |
Description

Input
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
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
Source
[Submit] [Go Back] [Status] [Discuss]
【POJ】【2068】Art Gallery的更多相关文章
- 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...
- 【POJ 1459 power network】
不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...
- 【POJ 2728 Desert King】
Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...
- 【POJ 2976 Dropping tests】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...
- 【POJ 3080 Blue Jeans】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...
- 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)
1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- 【POJ 2823 Sliding Window】 单调队列
题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...
- 【POJ 2406 Power Strings】
Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...
- poj 1279 -- Art Gallery (半平面交)
鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
随机推荐
- Educational Codeforces Round 44 (Rated for Div. 2) F - Isomorphic Strings
F - Isomorphic Strings 题目大意:给你一个长度为n 由小写字母组成的字符串,有m个询问, 每个询问给你两个区间, 问你xi,yi能不能形成映射关系. 思路:这个题意好难懂啊... ...
- hdoj1050 Moving Tables(贪心)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1050 题意 有一条走廊,走廊两边各有200个房间,一边的房间编号是奇数,另一边是偶数.现在有n个箱子需 ...
- 高仿360界面的实现(用纯XML和脚本实现)
源码下载:360UI 本项目XML的桌面渲染依赖GQT开源项目(请感兴趣的朋友加入QQ讨论群:101189702,在群共享文件里下载GQT源码),以下是360界面实现的全部XML代码,所有的代码都在3 ...
- MVP模型
MVP模型一般要创建三个文件夹:View.Interactor(Model).Presenter 每个部分都有其接口和实现类,就是为了方便回调 这里做一个登陆界面为例子: 接口: Interactor ...
- Windows-caffe配置
我在博客园的第一篇博客开始了,好紧张,好激动,好淫荡...哈哈O(∩_∩)O哈! 下面开始进入正题.配置环境为windows7+cuda7.5+vs2013+matlab2014a 之前用的happy ...
- shell cut
使用说明cut 命令从文件的每一行剪切字节.字符和字段并将这些字节.字符和字段写至标准输出.如果不指定 File 参数,cut 命令将读取标准输入.必须指定 -b.-c 或 -f 标志之一. 主要参数 ...
- NetCore+Dapper WebApi架构搭建(四):仓储的依赖注入
上一节我们讲到实体,仓储接口和仓储接口的实现需要遵循约定的命名规范,不仅是规范,而且为了依赖注入,现在我们实现仓储的依赖注入 在NetCore WebApi项目中新添加一个文件夹(Unit),当然你也 ...
- Qt Quick快速入门之qml与C++交互
C++中使用qml对象,直接使用findChild获取qml对象,然后调用setProperty方法设置属性,当然必须在加载qml之后才能使用,不然findChild找不到对象,用法如下. engin ...
- Spring Boot 运作原理
Spring Boot 运作原理 1.Spring Boot 简介 SpringBoot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了 ...
- python配置文件操作——configparser模块
# -*- coding: utf-8 -*- ''' Version : Python27 Author : Spring God Date : 2012-4-26 Info : 配置文件ini所在 ...