题意

PDF

分析

可以看成直线切割多边形,直接维护。

对每个多边形考虑每条边和每个点即可。

时间复杂度?不过\(n,m \leq 20\)这种数据怎么都过了。据说是\(O(n^3)\)的,而且常数也挺小。

一般的比赛估计不会出这种vector套vector的神题。

代码

注意初始化的时候的那个初始长方形的点必须按逆时针顺序来插入。

我写反了,导致调了一晚上。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef long long ll; co double eps=1e-8; int dcmp(double x)
{
return fabs(x)<eps?0:(x<0?-1:1);
} struct Point
{
double x,y; Point(double x=0,double y=0)
:x(x),y(y){};
};
typedef Point Vector;
typedef vector<Point> Polygon; Vector operator+(co Vector&A,co Vector&B)
{
return Vector(A.x+B.x,A.y+B.y);
} Vector operator-(co Vector&A,co Vector&B)
{
return Vector(A.x-B.x,A.y-B.y);
} Vector operator*(co Vector&A,double p)
{
return Vector(A.x*p,A.y*p);
} double Dot(co Vector&A,co Vector&B)
{
return A.x*B.x+A.y*B.y;
} double Cross(co Vector&A,co Vector&B)
{
return A.x*B.y-A.y*B.x;
} double Length2(co Vector&A)
{
return Dot(A,A);
} Point LineLineIntersection(co Point&P,co Vector&v,co Point&Q,co Vector&w)
{
Vector u=P-Q;
double t=Cross(w,u)/Cross(v,w);
return P+v*t;
} bool OnSegment(co Point&p,co Point&a1,co Point&a2)
{
return dcmp(Cross(a1-p,a2-p))==0&&dcmp(Dot(a1-p,a2-p))<0;
} double PolygonArea(co Polygon&poly)
{
double area=0;
int n=poly.size();
for(int i=1;i<n-1;++i)
area+=Cross(poly[i]-poly[0],poly[(i+1)%n]-poly[0]);
return area/2;
} Polygon CutPolygon(co Polygon&poly,co Point&A,co Point&B)
{
Polygon newpoly;
int n=poly.size();
for(int i=0;i<n;++i)
{
co Point&C=poly[i];
co Point&D=poly[(i+1)%n];
if(dcmp(Cross(B-A,C-A))>=0)
newpoly.push_back(C);
if(dcmp(Cross(B-A,C-D))!=0)
{
Point ip=LineLineIntersection(A,B-A,C,D-C);
if(OnSegment(ip,C,D))
newpoly.push_back(ip);
}
}
return newpoly;
} int PointInPolygon(co Point&p,co Polygon&v)
{
int wn=0;
int n=v.size();
for(int i=0;i<n;++i)
{
if(OnSegment(p,v[i],v[(i+1)%n]))
return -1;
int k=dcmp(Cross(v[(i+1)%n]-v[i],p-v[i]));
int d1=dcmp(v[i].y-p.y);
int d2=dcmp(v[(i+1)%n].y-p.y);
if(k>0&&d1<=0&&d2>0)
++wn;
if(k<0&&d2<=0&&d1>0)
--wn;
}
if(wn!=0)
return 1;
return 0;
} bool InCircle(co Point&p,co Point&center,double R)
{
return dcmp(Length2(p-center)-R*R)<0;
} int LineCircleIntersection(co Point&A,co Point&B,co Point&C,double r,double&t1,double&t2)
{
double a=B.x-A.x,
b=A.x-C.x,
c=B.y-A.y,
d=A.y-C.y; double e=a*a+c*c,
f=2*(a*b+c*d),
g=b*b+d*d-r*r,
delta=f*f-4*e*g;
if(dcmp(delta)<0)
return 0;
if(dcmp(delta)==0)
{
t1=t2=-f/(2*e);
return 1;
}
t1=(-f-sqrt(delta))/(2*e);
t2=(-f+sqrt(delta))/(2*e);
return 2;
} bool CircleIntersectSegment(co Point&A,co Point&B,co Point&p,double R)
{
double t1,t2;
int c=LineCircleIntersection(A,B,p,R,t1,t2);
if(c<=1)
return 0;
if(dcmp(t1)>0&&dcmp(t1-1)<0)
return 1;
if(dcmp(t2)>0&&dcmp(t2-1)<0)
return 1;
return 0;
} vector<Polygon> pieces,new_pieces; void Cut(int x1,int y1,int x2,int y2)
{
new_pieces.clear();
for(int i=0;i<pieces.size();++i)
{
Polygon left=CutPolygon(pieces[i],Point(x1,y1),Point(x2,y2));
Polygon right=CutPolygon(pieces[i],Point(x2,y2),Point(x1,y1));
if(left.size()>=3)
new_pieces.push_back(left);
if(right.size()>=3)
new_pieces.push_back(right);
// cerr<<"left="<<endl;
// for(int j=0;j<left.size();++j)
// cerr<<" "<<left[j].x<<","<<left[j].y;
// cerr<<endl;
// cerr<<"right="<<endl;
// for(int j=0;j<right.size();++j)
// cerr<<" "<<right[j].x<<","<<right[j].y;
// cerr<<endl;
}
pieces=new_pieces;
} bool DiscIntersectPolygon(co Polygon&poly,co Point&p,double R)
{
if(PointInPolygon(p,poly)!=0)
return 1;
if(InCircle(poly[0],p,R))
return 1;
int n=poly.size();
for(int i=0;i<n;++i)
{
if(CircleIntersectSegment(poly[i],poly[(i+1)%n],p,R))
return 1;
if(InCircle((poly[i]+poly[(i+1)%n])*0.5,p,R))
return 1;
}
return 0;
} void Query(co Point&p,int R)
{
vector<double>ans;
for(int i=0;i<pieces.size();++i)
if(DiscIntersectPolygon(pieces[i],p,R))
ans.push_back(fabs(PolygonArea(pieces[i])));
printf("%d",ans.size());
sort(ans.begin(),ans.end());
for(int i=0;i<ans.size();++i)
printf(" %.2lf",ans[i]);
printf("\n");
} int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n,m,L,W;
while(read(n)|read(m)|read(L)|read(W))
{
// cerr<<"n="<<n<<" m="<<m<<" L="<<L<<" W="<<W<<endl;
pieces.clear(); Polygon bbox;
bbox.push_back(Point(0,0)); // edit 1:must follow the order
bbox.push_back(Point(L,0));
bbox.push_back(Point(L,W));
bbox.push_back(Point(0,W));
pieces.push_back(bbox); for(int i=0;i<n;++i)
{
int x1,y1,x2,y2;
read(x1),read(y1),read(x2),read(y2);
// cerr<<"x1="<<x1<<" y1="<<y1<<" x2="<<x2<<" y2="<<y2<<endl;
Cut(x1,y1,x2,y2);
// for(int i=0;i<pieces.size();++i)
// {
// cerr<<i<<" poly="<<endl;
// for(int j=0;j<pieces[i].size();++j)
// cerr<<" "<<pieces[i][j].x<<","<<pieces[i][j].y;
// cerr<<endl;
// }
} for(int i=0;i<m;++i)
{
int x,y,R;
read(x),read(y),read(R);
Query(Point(x,y),R);
}
printf("\n");
}
return 0;
}

UVA12296 Pieces and Discs的更多相关文章

  1. uva 12296 Pieces and Discs

    题意: 有个矩形,左下角(0,0),左上角(L,W). 思路: 除了圆盘之外,本题的输入也是个PSLG,因此可以按照前面叙述的算法求出各个区域:只需把线段视为直线,用切割凸多边形的方法 :每次读入线段 ...

  2. uva 12296 Pieces and Discs (Geometry)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. HITOJ 2662 Pieces Assignment(状压DP)

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  4. 1.4.8 拼凑在一起(putting the pieces together)

    putting the pieces together 在最高的级别,schema.xml结构如下, <schema> <types> <fields> <u ...

  5. Pizza pieces

    Pizza pieces Description In her trip to Italy, Elizabeth Gilbert made it her duty to eat perfect piz ...

  6. HDU 4628 Pieces(DP + 状态压缩)

    Pieces 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4628 题目大意:给定一个字符串s,如果子序列中有回文,可以一步删除掉它,求把整个序列删除 ...

  7. Codeforces 328B-Sheldon and Ice Pieces(馋)

    B. Sheldon and Ice Pieces time limit per test 1 second memory limit per test 256 megabytes input sta ...

  8. 2017 NAIPC A:Pieces of Parentheses

    my team solve the problem in the contest with similar ideathis is a more deep analysis The main idea ...

  9. hdu 4628 Pieces 状态压缩dp

    Pieces Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

随机推荐

  1. 【WIN7】windows\system32 下的几乎所有文件的简单说明【1】

    1: aclui.dll .....Security Descriptor Editor,没有它,注册表编缉器会无法运行 2: ACTIVEDS.DLL .....(ADs 路由层 DLL). 没有它 ...

  2. VRChat简易教程4-使用VRC的接口实现物体的移动(VRC的action和trigger接口)

    这个教程我们学习如何实现载具的驾驶 一.准备工作 1 最简单的载具驾驶需要至少两个元素,一是需要一个载具,二是需要一个前进的按钮(这里我们只做前进功能),为了直观的能感受到载具的移动,我们还得创造一个 ...

  3. javascript-实现简单瀑布流

    直接上代码: <style> *{ margin:0; padding:0; } .waterfall_item{ border:solid 3px #ccc; box-shadow:1p ...

  4. COS-7设备管理

    操作系统(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才能运行.   操作系 ...

  5. 简单介绍java Enumeration(转)

    Enumeration接口 Enumeration接口本身不是一个数据结构.但是,对其他数据结构非常重要. Enumeration接口定义了从一个数据结构得到连续数据的手段.例如,Enumeratio ...

  6. Spring_IOC&DI概述

  7. Your app uses or references the following non-public APIs的解决方案

    之前接了一个旧的项目,代码混乱,年代久远,不得不吐槽一波,好不容易改完需求提交代码,说用到了non-public APIs,搞了好久终于找到地方了,下面是我的解决过程,让大家少走弯路: 下面的被驳回的 ...

  8. E - Water Distribution

    E - Water Distribution 题目大意: 有\(N\)座城市,给定这\(N\)座城市的坐标和初始的水量\(x_i,y_i,a_i\),在两个城市之间运水的花费是两个城市的欧几里得距离. ...

  9. 【bzoj1009】[HNOI2008]GT考试(矩阵快速幂优化dp+kmp)

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1009 这道题一看数据范围:$ n<=10^9 $,显然不是数学题就是矩乘快速幂优 ...

  10. Hibernate常见优化策略

    ① 制定合理的缓存策略(二级缓存.查询缓存). ② 采用合理的Session管理机制. ③ 尽量使用延迟加载特性. ④ 设定合理的批处理参数. ⑤ 如果可以,选用UUID作为主键生成器. ⑥ 如果可以 ...