POJ 1279
发现好多半平面交用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的更多相关文章
- poj 1279 半平面交核面积
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6668 Accepted: 2725 Descr ...
- poj 1279 Art Gallery - 求多边形核的面积
/* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...
- 【POJ 1279】Art Gallery
http://poj.org/problem?id=1279 裸的半平面交的模板,按极角排序后维护一个双端队列,不要忘了最后要去除冗余,即最后一条边(或者更多的边)一定在双端队列里,但它不一定构成半平 ...
- poj 1279 -- Art Gallery (半平面交)
鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- POJ 1279 Art Gallery 半平面交/多边形求核
http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...
- 半平面交 (poj 1279(第一道半平面NlogN)完整注释 )
半平面交的O(nlogn)算法(转载) 求n个半平面的交有三种做法: 第一种就是用每个平面去切割已有的凸多边形,复杂度O(n^2). 第二种就是传说中的分治算法.将n个半平面分成两个部分,分别求完交之 ...
- poj 1279 Art Gallery (Half Plane Intersection)
1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...
- POJ 1279 Art Gallery(半平面交)
题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...
- POJ 1279 Art Gallery(半平面交求多边形核的面积)
题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...
- Art Gallery - POJ 1279(求内核面积)
同上面几道题差不多,需要先求出来内核,然后直接用叉积求出来面积即可. 代码如下: #include<iostream> #include<string.h> #include& ...
随机推荐
- python关于文件的操作
总是记不住API.昨晚写的时候用到了这些,但是没记住,于是就索性整理一下吧: python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Pyth ...
- PCB MVC启动顺序与各层之间数据传递对象关系
准备着手基于MVC模式写一套Web端流程指示查看,先着手开发WebAPI打通数据接口,后续可扩展手机端 这里将MVC基本关系整理如下: 一.MVC启动顺序 二.MVC各层之间数据传递对象关系
- lodop使用
根据相应的操作系统,安装install_lodop32.exe文件,它里面包含两个exe文件install_lodop32.exe和install_lodop64.exe,在页面的头部中引入: < ...
- hdu3555Bomb(数位dp)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- Nightmare --- 炸弹时间复位
题目大意: 该题为走迷宫,其条件有如下6个: 1, 迷宫用二维数组来表示: 2, 人走动时不能越界,不能在墙上走: 3, 当走到出口时,若剩余时间恰好为0,则失败: 4, 找到炸弹复位装置,若剩余时间 ...
- 7.Flask-上传文件和访问上传的文件
1.1.上传文件和访问上传的文件 upload_file_demo.py from flask import Flask,request,render_template import os from ...
- DeltaFish 校园物资共享平台 第六次小组会议
DeltaFish 校园物资共享平台 第六次小组会议 记录人:娄雨禛 2018.6.3 任务进度(2018.5.28-2018.6.3) 前端 李鑫:商品详情界面设计.总体配色分析 刘鼎乾:卖家页面初 ...
- AI:IPPR的数学表示-CNN方法
前言: 随着超量类别PR和高精度的需求,人工特征方法局限性凸显出来,固定的特征hash压缩映射因其压缩损失.表现为特定的特征hash方法,在海量的同类数据集上近邻特性变差,而在不同类别的数据上面隔离性 ...
- Functor and Monad in Swift
I have been trying to teach myself Functional Programming since late 2013. Many of the concepts are ...
- efcore 控制台迁移架构
添加 nuget 包: Microsoft.EntityFrameworkCore.Design Microsoft.EntityFrameworkCore.SqlServer Microsoft.E ...