计算几何/半平面交


  裸的半平面交,关于半平面交的入门请看神犇博客: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 ;
}
Art Gallery
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5805   Accepted: 2455

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

Source

[Submit]   [Go Back]   [Status]   [Discuss]

  

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

  1. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  2. 【POJ 1459 power network】

    不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...

  3. 【POJ 2728 Desert King】

    Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...

  4. 【POJ 2976 Dropping tests】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...

  5. 【POJ 3080 Blue Jeans】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...

  6. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  7. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  8. 【POJ 2823 Sliding Window】 单调队列

    题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...

  9. 【POJ 2406 Power Strings】

    Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...

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

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

随机推荐

  1. mysql 插入时带判断条件

    INSERT INTO table (f1 ,f2 ,f3) ,'a', FROM DUAL WHERE NOT EXISTS ( FROM table2 where a = b) DUAL 为临时表 ...

  2. 在android studio中集成javah, ndk-build进行JNI开发

    最近在搞一个android上控制LED灯闪烁的功能,用到了串口编程,搜索了一下,发现Google发布了一个demo,android-serialport-api.有现成的代码和APK,要想自己改JNI ...

  3. java 里的内部类

    java里的内部类通常能帮我们隐藏一些具体实现,体现良好的封装效果. 内部类又分几种: 1.普通内部类 2.局部内部类 3.匿名内部类 4.静态内部类 普通内部类 先来看第一种普通的内部类,这种内部类 ...

  4. 牛客练习赛1 C - 圈圈

    链接:https://www.nowcoder.com/acm/contest/2/C来源:牛客网 题目描述 shy有一个队列a[1], a[2],…,a[n].现在我们不停地把头上的元素放到尾巴上. ...

  5. python爬虫+词云图,爬取网易云音乐评论

    又到了清明时节,用python爬取了网易云音乐<清明雨上>的评论,统计词频和绘制词云图,记录过程中遇到一些问题 爬取网易云音乐的评论 一开始是按照常规思路,分析网页ajax的传参情况.看到 ...

  6. 【基本功】深入剖析Swift性能优化

    简介 2014年,苹果公司在WWDC上发布Swift这一新的编程语言.经过几年的发展,Swift已经成为iOS开发语言的“中流砥柱”,Swift提供了非常灵活的高级别特性,例如协议.闭包.泛型等,并且 ...

  7. 美团客户端响应式框架EasyReact开源啦

    前言 EasyReact 是一款基于响应式编程范式的客户端开发框架,开发者可以使用此框架轻松地解决客户端的异步问题. 目前 EasyReact 已在美团和大众点评客户端的部分业务中进行了实践,并且持续 ...

  8. luoguP3185 [HNOI2007]分裂游戏 枚举 + 博弈论

    每个位置的瓶子中的每个石子是一个独立的游戏 只要计算出他们的\(sg\)值即可 至于方案数,反正不多\(n^3\)暴力枚举即可 反正怎么暴力都能过啊 复杂度\(O(Tn^3)\) #include & ...

  9. [SPOJ-BEADS]Glass Beads

    来源: CE1998 题目大意: 求字符串最小表示. 思路: 字符串复制一遍接在后面,构建SAM,然后每次跑小的转移. 跑n次以后就跑到了最小表示的末尾,用该状态的len值减去n就是最小表示的起始位置 ...

  10. (Nginx和PHP下)URL重写,TP实现URL重写

    UrlRewrite就是我们通常说的地址重写,用户得到的全部都是经过处理后的URL地址. 优点 一:提高安全性,可以有效的避免一些参数名.ID等完全暴露在用户面前,如果用户随便乱输的话,不符合规则的话 ...