发现好多半平面交用N^2的增量法都能过诶。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; const int MAXN=1550;
const double eps=1e-8;
struct point {
double x,y;
};
point pts[MAXN],p[MAXN],q[MAXN];
int ansCnt,curCnt,n; double DB(double d){
if(d>eps) return 1;
if(d<-eps) return -1;
return 0;
} double getArea(point *tmp,int n){
double ans=0;
for(int i=1;i<=n;i++)
ans+=(tmp[i].x*tmp[i+1].y-tmp[i+1].x*tmp[i].y);
return ans/2;
} void Adjust(){
for(int i=1;i<(n+1)/2;i++)
swap(pts[i],pts[n-i]);
} void initial(){
double area=getArea(pts,n);
if(DB(area)>=0) Adjust();
for(int i=1;i<=n;i++)
p[i]=pts[i];
p[n+1]=p[1];
p[0]=p[n];
ansCnt=n;
} void getline(point x,point y,double &a,double &b,double &c){
a=y.y-x.y;
b=x.x-y.x;
c=x.y*y.x-x.x*y.y;
} point intersect(point x,point y,double a,double b,double c){
double u=fabs(a*x.x+b*x.y+c);
double v=fabs(a*y.x+b*y.y+c);
point pt;
pt.x=(x.x*v+y.x*u)/(u+v);
pt.y=(x.y*v+y.y*u)/(u+v);
return pt;
} void cut(double a,double b,double c){
curCnt=0;
for(int i=1;i<=ansCnt;i++){
if(DB(a*p[i].x+b*p[i].y+c)>=0) q[++curCnt]=p[i];
else {
if(DB(a*p[i-1].x+b*p[i-1].y+c)>0) q[++curCnt]=intersect(p[i],p[i-1],a,b,c);
if(DB(a*p[i+1].x+b*p[i+1].y+c)>0) q[++curCnt]=intersect(p[i],p[i+1],a,b,c);
}
}
for(int i=1;i<=curCnt;i++){
p[i]=q[i];
}
ansCnt=curCnt;
p[ansCnt+1]=p[1]; p[0]=p[ansCnt];
} void slove(){
initial();
for(int i=1;i<=n;i++){
double a,b,c;
getline(pts[i],pts[i+1],a,b,c);
cut(a,b,c);
}
} int main(){
int cas=0;
int t;
scanf("%d",&t);
while(t--){
scanf("%d\n",&n);
cas++;
for(int i=1;i<=n;i++)
scanf("%lf%lf",&pts[i].x,&pts[i].y);
pts[n+1]=pts[1];
slove();
double as=getArea(p,ansCnt);
printf("%.2lf\n",fabs(as));
}
return 0;
}

  

POJ 1279的更多相关文章

  1. poj 1279 半平面交核面积

    Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6668   Accepted: 2725 Descr ...

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

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

  3. 【POJ 1279】Art Gallery

    http://poj.org/problem?id=1279 裸的半平面交的模板,按极角排序后维护一个双端队列,不要忘了最后要去除冗余,即最后一条边(或者更多的边)一定在双端队列里,但它不一定构成半平 ...

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

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

  5. POJ 1279 Art Gallery 半平面交/多边形求核

    http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...

  6. 半平面交 (poj 1279(第一道半平面NlogN)完整注释 )

    半平面交的O(nlogn)算法(转载) 求n个半平面的交有三种做法: 第一种就是用每个平面去切割已有的凸多边形,复杂度O(n^2). 第二种就是传说中的分治算法.将n个半平面分成两个部分,分别求完交之 ...

  7. poj 1279 Art Gallery (Half Plane Intersection)

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

  8. POJ 1279 Art Gallery(半平面交)

    题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...

  9. POJ 1279 Art Gallery(半平面交求多边形核的面积)

    题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...

  10. Art Gallery - POJ 1279(求内核面积)

    同上面几道题差不多,需要先求出来内核,然后直接用叉积求出来面积即可. 代码如下: #include<iostream> #include<string.h> #include& ...

随机推荐

  1. bzoj 3209 花神的数论题 —— 数位DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3209 算是挺简单的数位DP吧,但还是花了好久才弄明白... 又参考了博客:https://b ...

  2. 【DP、线段树优化】琪露诺

    跟去年(2017)PJ第四题几乎是一样的?/吐血 DP方程可以很简单的推出来,f[i]=max{f[k]}+a[i] 然而这样做是O(n^2)的 看一下数据,200000的话要不nlogn 要不n 由 ...

  3. A - Design Tutorial: Learn from Math(哥德巴赫猜想)

    Problem description One way to create a task is to learn from math. You can generate some random mat ...

  4. Python启动浏览器Firefox\Chrome\IE

    # -*- coding:utf-8 -*- import os import selenium from selenium import webdriver from selenium.webdri ...

  5. MVC微信浏览器图片上传(img转Base64)

    因公司业务需要,需要做一个微信公众号里的图片上传功能,主要用到的技术就是 img转base64 上到服务器 话不多说, 贴代码 先看前端显示出来的东西 OK 图片不重要,看代码 <!--微信图片 ...

  6. swift-自定义TabBar工具栏

    class EBTAppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(ap ...

  7. Django学习案例一(blog):二. 连接数据库

    本例使用了django默认的sqlite3数据库,配置文件不需要作调整: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite ...

  8. ESB报文自动生成工具

    为了提高日常工作效率,自己在闲暇时间写了一款工具,功能界面如下图所示: 从ESB文档中复制报文字段.字段类型.报文字段注释,选择生成文件路径并输入文件名: 输入完毕后点击生成按钮,自动生成Contex ...

  9. Android学习——动态注册监听网络变化

    新建一个BroadcastTest项目,然后修改MainActivity中的代码,如下: public class MainActivity extends AppCompatActivity { p ...

  10. dubbo之线程模型

    事件处理线程说明 如果事件处理的逻辑能迅速完成,并且不会发起新的IO请求,比如只是在内存中记个标识,则直接在IO线程上处理更快,因为减少了线程池调度. 但如果事件处理逻辑较慢,或者需要发起新的IO请求 ...