Harry Potter and J.K.Rowling(半平面交+圆和矩形交)
Harry Potter and J.K.Rowling
http://acm.hdu.edu.cn/showproblem.php?pid=3982
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1094 Accepted Submission(s): 357
Rowling had lots of friends, and she had a knife to cut the cake into many pieces. On the cake there was a cherry. After several cuts, the piece with the cherry was left for Rowling. Before she enjoyed it, she wondered how large this piece was, i.e., she wondered how much percentage of the cake the piece with the only cherry has.
T test cases follow. The first line of each test case has one number r (1 <= r <= 10000) and one integer n (0 <= n <= 2000), indicating the radius of the cake and the number of knife cuts. n lines follow. The i-th line has four numbers, x1, y1, x2, y2. (x1, y1) and (x2, y2) are two points on the i-th cut. (-10000 <= x1, y1, x2, y2 <= 10000) The last line of each case has two number x, y, indicating the coordinate(x, y) of the cherry.
Technical Specification
1. R, x1, y2, x2, y2, x, y all have two digits below decimal points.
2. The center of the cake is always on the point (0, 0).
3. The cherry was always on the cake and would not be on the knife cuts.
附上测试数据,半平面交模板题
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-;
const double INF=1e20;
const double PI=acos(-1.0);
const int maxp=;
int sgn(double x){
if(fabs(x)<eps) return ;
if(x<) return -;
else return ;
}
inline double sqr(double x){return x*x;}
struct Point{
double x,y;
Point(){}
Point(double _x,double _y){
x=_x;
y=_y;
}
void input(){
scanf("%lf %lf",&x,&y);
}
void output(){
printf("%.2f %.2f\n",x,y);
}
bool operator == (const Point &b)const{
return sgn(x-b.x) == && sgn(y-b.y)== ;
}
bool operator < (const Point &b)const{
return sgn(x-b.x)==?sgn(y-b.y)<:x<b.x;
}
Point operator - (const Point &b)const{
return Point(x-b.x,y-b.y);
}
//叉积
double operator ^ (const Point &b)const{
return x*b.y-y*b.x;
}
//点积
double operator * (const Point &b)const{
return x*b.x+y*b.y;
}
//返回长度
double len(){
return hypot(x,y);
}
//返回长度的平方
double len2(){
return x*x+y*y;
}
//返回两点的距离
double distance(Point p){
return hypot(x-p.x,y-p.y);
}
Point operator + (const Point &b)const{
return Point(x+b.x,y+b.y);
}
Point operator * (const double &k)const{
return Point(x*k,y*k);
}
Point operator / (const double &k)const{
return Point(x/k,y/k);
} //计算pa和pb的夹角
//就是求这个点看a,b所成的夹角
///LightOJ1202
double rad(Point a,Point b){
Point p=*this;
return fabs(atan2(fabs((a-p)^(b-p)),(a-p)*(b-p)));
}
//化为长度为r的向量
Point trunc(double r){
double l=len();
if(!sgn(l)) return *this;
r/=l;
return Point(x*r,y*r);
}
//逆时针转90度
Point rotleft(){
return Point(-y,x);
}
//顺时针转90度
Point rotright(){
return Point(y,-x);
}
//绕着p点逆时针旋转angle
Point rotate(Point p,double angle){
Point v=(*this) -p;
double c=cos(angle),s=sin(angle);
return Point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
}
}; struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e){
s=_s;
e=_e;
}
bool operator==(Line v){
return (s==v.s)&&(e==v.e);
}
//根据一个点和倾斜角angle确定直线,0<=angle<pi
Line(Point p,double angle){
s=p;
if(sgn(angle-PI/)==){
e=(s+Point(,));
}
else{
e=(s+Point(,tan(angle)));
}
}
//ax+by+c=0;
Line(double a,double b,double c){
if(sgn(a)==){
s=Point(,-c/b);
e=Point(,-c/b);
}
else if(sgn(b)==){
s=Point(-c/a,);
e=Point(-c/a,);
}
else{
s=Point(,-c/b);
e=Point(,(-c-a)/b);
}
}
void input(){
s.input();
e.input();
}
void adjust(){
if(e<s) swap(s,e);
}
//求线段长度
double length(){
return s.distance(e);
}
//返回直线倾斜角 0<=angle<pi
double angle(){
double k=atan2(e.y-s.y,e.x-s.x);
if(sgn(k)<) k+=PI;
if(sgn(k-PI)==) k-=PI;
return k;
}
//点和直线的关系
//1 在左侧
//2 在右侧
//3 在直线上
int relation(Point p){
int c=sgn((p-s)^(e-s));
if(c<) return ;
else if(c>) return ;
else return ;
}
//点在线段上的判断
bool pointonseg(Point p){
return sgn((p-s)^(e-s))==&&sgn((p-s)*(p-e))<=;
}
//两向量平行(对应直线平行或重合)
bool parallel(Line v){
return sgn((e-s)^(v.e-v.s))==;
}
//两线段相交判断
//2 规范相交
//1 非规范相交
//0 不相交
int segcrossseg(Line v){
int d1=sgn((e-s)^(v.s-s));
int d2=sgn((e-s)^(v.e-s));
int d3=sgn((v.e-v.s)^(s-v.s));
int d4=sgn((v.e-v.s)^(e-v.s));
if((d1^d2)==-&&(d3^d4)==-) return ;
return (d1==&&sgn((v.s-s)*(v.s-e))<=||
d2==&&sgn((v.e-s)*(v.e-e))<=||
d3==&&sgn((s-v.s)*(s-v.e))<=||
d4==&&sgn((e-v.s)*(e-v.e))<=);
}
//直线和线段相交判断
//-*this line -v seg
//2 规范相交
//1 非规范相交
//0 不相交
int linecrossseg(Line v){
int d1=sgn((e-s)^(v.s-s));
int d2=sgn((e-s)^(v.e-s));
if((d1^d2)==-) return ;
return (d1==||d2==);
}
//两直线关系
//0 平行
//1 重合
//2 相交
int linecrossline(Line v){
if((*this).parallel(v))
return v.relation(s)==;
return ;
}
//求两直线的交点
//要保证两直线不平行或重合
Point crosspoint(Line v){
double a1=(v.e-v.s)^(s-v.s);
double a2=(v.e-v.s)^(e-v.s);
return Point((s.x*a2-e.x*a1)/(a2-a1),(s.y*a2-e.y*a1)/(a2-a1));
}
//点到直线的距离
double dispointtoline(Point p){
return fabs((p-s)^(e-s))/length();
}
//点到线段的距离
double dispointtoseg(Point p){
if(sgn((p-s)*(e-s))<||sgn((p-e)*(s-e))<)
return min(p.distance(s),p.distance(e));
return dispointtoline(p);
}
//返回线段到线段的距离
//前提是两线段不相交,相交距离就是0了
double dissegtoseg(Line v){
return min(min(dispointtoseg(v.s),dispointtoseg(v.e)),min(v.dispointtoseg(s),v.dispointtoseg(e)));
}
//返回点P在直线上的投影
Point lineprog(Point p){
return s+(((e-s)*((e-s)*(p-s)))/((e-s).len2()));
}
//返回点P关于直线的对称点
Point symmetrypoint(Point p){
Point q=lineprog(p);
return Point(*q.x-p.x,*q.y-p.y);
}
}; struct circle{
Point p;
double r;
circle(){}
circle(Point _p,double _r){
p=_p;
r=_r;
} circle(double x,double y,double _r){
p=Point(x,y);
r=_r;
} circle(Point a,Point b,Point c){///三角形的外接圆
Line u=Line((a+b)/,((a+b)/)+((b-a).rotleft()));
Line v=Line((b+c)/,((b+c)/)+((c-b).rotleft()));
p=u.crosspoint(v);
r=p.distance(a);
} circle(Point a,Point b,Point c,bool t){///三角形的内切圆
Line u,v;
double m=atan2(b.y-a.y,b.x-a.x),n=atan2(c.y-a.y,c.x-a.x);
u.s=a;
u.e=u.s+Point(cos((n+m)/),sin((n+m)/));
v.s=b;
m=atan2(a.y-b.y,a.x-b.x),n=atan2(c.y-b.y,c.x-b.x);
v.e=v.s+Point(cos((n+m)/),sin((n+m)/));
p=u.crosspoint(v);
r=Line(a,b).dispointtoseg(p);
} void input(){
p.input();
scanf("%lf",&r);
} void output(){
printf("%.2f %.2f %.2f\n",p.x,p.y,r);
} bool operator==(circle v){
return (p==v.p)&&sgn(r-v.r)==;
} bool operator<(circle v)const{
return ((p<v.p)||((p==v.p)&&sgn(r-v.r)<));
} double area(){
return PI*r*r;
} double circumference(){ ///周长
return *PI*r;
} int relation(Point b){///点和圆的关系 0圆外 1圆上 2圆内
double dst=b.distance(p);
if(sgn(dst-r)<) return ;
else if(sgn(dst-r)==) return ;
return ;
} int relationseg(Line v){///线段和圆的关系,比较的是圆心到线段的距离和半径的关系
double dst=v.dispointtoseg(p);
if(sgn(dst-r)<) return ;
else if(sgn(dst-r)==) return ;
return ;
} int relationline(Line v){///直线和圆的关系,比较的是圆心到直线的距离和半径的关系
double dst=v.dispointtoline(p);
if(sgn(dst-r)<) return ;
else if(sgn(dst-r)==) return ;
return ;
} int relationcircle(circle v){///两圆的关系 5相离 4外切 3相交 2内切 1内含
double d=p.distance(v.p);
if(sgn(d-r-v.r)>) return ;
if(sgn(d-r-v.r)==) return ;
double l=fabs(r-v.r);
if(sgn(d-r-v.r)<&&sgn(d-l)>) return ;
if(sgn(d-l)==) return ;
if(sgn(d-l)<) return ;
} int pointcrosscircle(circle v,Point &p1,Point &p2){///求两个圆的交点,0没有交点 1一个交点 2两个交点
int rel=relationcircle(v);
if(rel == || rel == ) return ;
double d=p.distance(v.p);
double l=(d*d+r*r-v.r*v.r)/*d;
double h=sqrt(r*r-l*l);
Point tmp=p+(v.p-p).trunc(l);
p1=tmp+((v.p-p).rotleft().trunc(h));
p2=tmp+((v.p-p).rotright().trunc(h));
if(rel == || rel == ) return ;
return ;
} int pointcrossline(Line v,Point &p1,Point &p2){///求直线和圆的交点,返回交点的个数
if(!(*this).relationline(v)) return ;
Point a=v.lineprog(p);
double d=v.dispointtoline(p);
d=sqrt(r*r-d*d);
if(sgn(d)==) {
p1=a;
p2=a;
return ;
}
p1=a+(v.e-v.s).trunc(d);
p2=a-(v.e-v.s).trunc(d);
return ;
} int getcircle(Point a,Point b,double r1,circle &c1,circle &c2){///得到过a,b两点,半径为r1的两个圆
circle x(a,r1),y(b,r1);
int t=x.pointcrosscircle(y,c1.p,c2.p);
if(!t) return ;
c1.r=c2.r=r;
return t;
} int getcircle(Line u,Point q,double r1,circle &c1,circle &c2){///得到与直线u相切,过点q,半径为r1的圆
double dis = u.dispointtoline(q);
if(sgn(dis-r1*)>) return ;
if(sgn(dis)==) {
c1.p=q+((u.e-u.s).rotleft().trunc(r1));
c2.p=q+((u.e-u.s).rotright().trunc(r1));
c1.r=c2.r=r1;
return ;
}
Line u1=Line((u.s+(u.e-u.s).rotleft().trunc(r1)),(u.e+(u.e-u.s).rotleft().trunc(r1)));
Line u2=Line((u.s+(u.e-u.s).rotright().trunc(r1)),(u.e+(u.e-u.s).rotright().trunc(r1)));
circle cc=circle(q,r1);
Point p1,p2;
if(!cc.pointcrossline(u1,p1,p2)) cc.pointcrossline(u2,p1,p2);
c1=circle(p1,r1);
if(p1==p2){
c2=c1;
return ;
}
c2=circle(p2,r1);
return ;
} int getcircle(Line u,Line v,double r1,circle &c1,circle &c2,circle &c3,circle &c4){///同时与直线u,v相切,半径为r1的圆
if(u.parallel(v)) return ;///两直线平行
Line u1=Line(u.s+(u.e-u.s).rotleft().trunc(r1),u.e+(u.e-u.s).rotleft().trunc(r1));
Line u2=Line(u.s+(u.e-u.s).rotright().trunc(r1),u.e+(u.e-u.s).rotright().trunc(r1));
Line v1=Line(v.s+(v.e-v.s).rotleft().trunc(r1),v.e+(v.e-v.s).rotleft().trunc(r1));
Line v2=Line(v.s+(v.e-v.s).rotright().trunc(r1),v.e+(v.e-v.s).rotright().trunc(r1));
c1.r=c2.r=c3.r=c4.r=r1;
c1.p=u1.crosspoint(v1);
c2.p=u1.crosspoint(v2);
c3.p=u2.crosspoint(v1);
c4.p=u2.crosspoint(v2);
return ;
} int getcircle(circle cx,circle cy,double r1,circle &c1,circle &c2){///同时与不相交圆 cx,cy相切,半径为r1的圆
circle x(cx.p,r1+cx.r),y(cy.p,r1+cy.r);
int t=x.pointcrosscircle(y,c1.p,c2.p);
if(!t) return ;
c1.r=c2.r=r1;
return t;
} int tangentline(Point q,Line &u,Line &v){///过一点作圆的切线(先判断点和圆的关系)
int x=relation(q);
if(x==) return ;
if(x==){
u=Line(q,q+(q-p).rotleft());
v=u;
return ;
}
double d=p.distance(q);
double l=r*r/d;
double h=sqrt(r*r-l*l);
u=Line(q,p+((q-p).trunc(l)+(q-p).rotleft().trunc(h)));
v=Line(q,p+((q-p).trunc(l)+(q-p).rotright().trunc(h)));
return ;
} double areacircle(circle v){///求两圆相交的面积
int rel=relationcircle(v);
if(rel >= ) return 0.0;
if(rel <= ) return min(area(),v.area());
double d=p.distance(v.p);
double hf=(r+v.r+d)/2.0;
double ss=*sqrt(hf*(hf-r)*(hf-v.r)*(hf-d));
double a1=acos((r*r+d*d-v.r*v.r)/(2.0*r*d));
a1=a1*r*r;
double a2=acos((v.r*v.r+d*d-r*r)/(2.0*v.r*d));
a2=a2*v.r*v.r;
return a1+a2-ss;
} double areatriangle(Point a,Point b){///求圆和三角形pab的相交面积
if(sgn((p-a)^(p-b))==) return 0.0;
Point q[];
int len=;
q[len++]=a;
Line l(a,b);
Point p1,p2;
if(pointcrossline(l,q[],q[])==){
if(sgn((a-q[])*(b-q[]))<) q[len++]=q[];
if(sgn((a-q[])*(b-q[]))<) q[len++]=q[];
}
q[len++]=b;
if(len== && sgn((q[]-q[])*(q[]-q[]))>) swap(q[],q[]);
double res=;
for(int i=;i<len-;i++){
if(relation(q[i])==||relation(q[i+])==){
double arg=p.rad(q[i],q[i+]);
res+=r*r*arg/2.0;
}
else{
res+=fabs((q[i]-p)^(q[i+]-p))/2.0;
}
}
return res;
}
}; struct polygon{
int n;
Point p[];
Line l[];
void input(int _n){
n=_n;
for(int i=;i<n;i++){
p[i].input();
}
} void add(Point q){
p[n++]=q;
} void getline(){
for(int i=;i<n;i++){
l[i]=Line(p[i],p[(i+)%n]);
}
} struct cmp{
Point p;
cmp(const Point &p0){p=p0;}
bool operator()(const Point &aa,const Point &bb){
Point a=aa,b=bb;
int d=sgn((a-p)^(b-p));
if(d==){
return sgn(a.distance(p)-b.distance(p))<;
}
return d>;
}
}; void norm(){///进行极角排序
Point mi=p[];
for(int i=;i<n;i++){
mi=min(mi,p[i]);
sort(p,p+n,cmp(mi));
}
} void getconvex(polygon &convex){///得到第一种凸包的方法,编号为0~n-1,可能要特判所有点共点或共线的特殊情况
sort(p,p+n);
convex.n=n;
for(int i=;i<min(n,);i++){
convex.p[i]=p[i];
}
if(convex.n==&&(convex.p[]==convex.p[])) convex.n--;
if(n<=) return;
int &top=convex.n;
top=;
for(int i=;i<n;i++){
while(top&&sgn((convex.p[top]-p[i])^(convex.p[top-]-p[i]))<) top--;
convex.p[++top]=p[i];
}
int temp=top;
convex.p[++top]=p[n-];
for(int i=n-;i>=;i--){
while(top!=temp&&sgn((convex.p[top]-p[i])^(convex.p[top-]-p[i]))<=) top--;
convex.p[++top]=p[i];
}
if(convex.n==&&(convex.p[]==convex.p[])) convex.n--;
convex.norm();
} void Graham(polygon &convex){///得到凸包的第二种方法
norm();
int &top=convex.n;
top=;
if(n==){
top=;
convex.p[]=p[];
return;
}
if(n==){
top=;
convex.p[]=p[];
convex.p[]=p[];
if(convex.p[]==convex.p[]) top--;
return;
}
convex.p[]=p[];
convex.p[]=p[];
top=;
for(int i=;i<n;i++){
while(top>&&sgn((convex.p[top-]-convex.p[top-])^(p[i]-convex.p[top-]))<=) top--;
convex.p[top++]=p[i];
}
if(convex.n== && (convex.p[]==convex.p[])) convex.n--;
} bool inconvex(){///判断是不是凸的
bool s[];
memset(s,false,sizeof(s));
for(int i=;i<n;i++){
int j=(i+)%n;
int k=(j+)%n;
s[sgn((p[j]-p[i])^(p[k]-p[i]))+]=true;
if(s[]&&s[]) return false;
}
return true;
} int relationpoint(Point q){///判断点和任意多边形的关系 3点上 2边上 1内部 0外部
for(int i=;i<n;i++){
if(p[i]==q) return ;
}
getline();
for(int i=;i<n;i++){
if(l[i].pointonseg(q)) return ;
}
int cnt=;
for(int i=;i<n;i++){
int j=(i+)%n;
int k=sgn((q-p[j])^(p[i]-p[j]));
int u=sgn(p[i].y-q.y);
int v=sgn(p[j].y-q.y);
if(k>&&u<&&v>=) cnt++;
if(k<&&v<&&u>=) cnt--;
}
return cnt!=;
} void convexcnt(Line u,polygon &po){///直线u切割凸多边形左侧 注意直线方向
int &top=po.n;
top=;
for(int i=;i<n;i++){
int d1=sgn((u.e-u.s)^(p[i]-u.s));
int d2=sgn((u.e-u.s)^(p[(i+)%n]-u.s));
if(d1>=) po.p[top++]=p[i];
if(d1*d2<)po.p[top++]=u.crosspoint(Line(p[i],p[(i+)%n]));
}
} double getcircumference(){///得到周长
double sum=;
for(int i=;i<n;i++){
sum+=p[i].distance(p[(i+)%n]);
}
return sum;
} double getarea(){///得到面积
double sum=;
for(int i=;i<n;i++){
sum+=(p[i]^p[(i+)%n]);
}
return fabs(sum)/;
} bool getdir(){///得到方向 1表示逆时针 0表示顺时针
double sum=;
for(int i=;i<n;i++){
sum+=(p[i]^p[(i+)%n]);
}
if(sgn(sum)>) return ;
return ;
} Point getbarycentre(){///得到重心
Point ret(,);
double area=;
for(int i=;i<n-;i++){
double tmp=(p[i]-p[])^(p[i+]-p[]);
if(sgn(tmp)==) continue;
area+=tmp;
ret.x+=(p[].x+p[i].x+p[i+].x)/*tmp;
ret.y+=(p[].y+p[i].y+p[i+].y)/*tmp;
}
if(sgn(area)) ret =ret/area;
return ret;
} double areacircle(circle c){///多边形和圆交的面积
double ans=;
for(int i=;i<n;i++){
int j=(i+)%n;
if(sgn((p[j]-c.p)^(p[i]-c.p))>=) ans+=c.areatriangle(p[i],p[j]);
else ans-=c.areatriangle(p[i],p[j]);
}
return fabs(ans);
} int relationcircle(circle c){///多边形和圆的关系 2圆完全在多边形内 1圆在多边形里面,碰到了多边形的边界 0其他
getline();
int x=;
if(relationpoint(c.p)!=) return ;
for(int i=;i<n;i++){
if(c.relationseg(l[i])==) return ;
if(c.relationseg(l[i])==) x=;
}
return x;
}
}; double cross(Point a,Point b,Point c){///ab x ac
return (b-a)^(c-a);
} double dot(Point a,Point b,Point c){///ab*ac;
return (b-a)*(c-a);
} /*double minRectangleCover(polygon A){///最小矩形面积覆盖 A必须是凸包
if(A.n<3) return 0.0;
A.p[A.n]==A.p[0];
double ans=-1;
int r=1,p=1,q;
for(int i=0;i<A.n;i++){ }
}*/ vector<Point> convexCut(const vector<Point>&ps,Point q1,Point q2){///直线切凸多边形,多边形是逆时针的,在q1q2的左侧
vector<Point>qs;
int n=ps.size();
for(int i=;i<n;i++){
Point p1=ps[i],p2=ps[(i+)%n];
int d1=sgn((q2-q1)^(p1-q1)),d2=sgn((q2-q1)^(p2-q1));
if(d1>=) qs.push_back(p1);
if(d1*d2<) qs.push_back(Line(p1,p2).crosspoint(Line(q1,q2)));
}
return qs;
} struct halfplane:public Line{
double angle;
halfplane(){}
halfplane(Point _s,Point _e){///表示向量s->e逆时针(左侧)的半平面
s=_s;
e=_e;
}
halfplane(Line v){
s=v.s;
e=v.e;
}
void calcangle(){
angle=atan2(e.y-s.y,e.x-s.x);
}
bool operator<(const halfplane &b)const{
return angle<b.angle;
}
}; struct halfplanes{
int n;
halfplane hp[];
Point p[];
int que[];
int st,ed;
void push(halfplane tmp){
hp[n++]=tmp;
} void unique(){///去重
int m=;
for(int i=;i<n;i++){
if(sgn(hp[i].angle-hp[i-].angle)!=) hp[m++]=hp[i];
else if(sgn((hp[m-].e-hp[m-].s)^(hp[i].s-hp[m-].s))>) hp[m-]=hp[i];
}
n=m;
}
bool halfplaneinsert(){
for(int i=;i<n;i++) hp[i].calcangle();
sort(hp,hp+n);
unique();
que[st=]=;
que[ed=]=;
p[]=hp[].crosspoint(hp[]);
for(int i=;i<n;i++){
while(st<ed&&sgn((hp[i].e-hp[i].s)^(p[ed]-hp[i].s))<) ed--;
while(st<ed&&sgn((hp[i].e-hp[i].s)^(p[st+]-hp[i].s))<) st++;
que[++ed]=i;
if(hp[i].parallel(hp[que[ed-]])) return false;
p[ed]=hp[i].crosspoint(hp[que[ed-]]);
}
while(st<ed&&sgn((hp[que[st]].e-hp[que[st]].s)^(p[ed]-hp[que[st]].s))<) ed--;
while(st<ed&&sgn((hp[que[ed]].e-hp[que[ed]].s)^(p[st+]-hp[que[ed]].s))<) st++;
if(st+>=ed) return false;
return true;
} void getconvex(polygon &con){///得到最后半平面交得到的凸多边形,要先调用halfplaneinsert()且返回true
p[st]=hp[que[st]].crosspoint(hp[que[ed]]);
con.n=ed-st+;
for(int j=st,i=;j<=ed;i++,j++){
con.p[i]=p[j];
}
}
}; struct circles{
circle c[];
double ans[];///ans[i]表示被覆盖了i次的面积
double pre[];
int n;
circles(){}
void add(circle cc){
c[n++]=cc;
} bool inner(circle x,circle y){///x包含在y中
if(x.relationcircle(y)!=) return ;
return sgn(x.r-y.r)<=?:;
} void init_or(){///圆的面积并去掉内含的圆
bool mark[]={};
int i,j,k=;
for(i=;i<n;i++){
for(j=;j<n;j++){
if(i!=j&&!mark[j]){
if(c[i]==c[j]||inner(c[i],c[j])) break;
}
}
if(j<n) mark[i]=;
}
for(i=;i<n;i++){
if(!mark[i]) c[k++]=c[i];
}
n=k;
} void init_add(){///圆的面积交去掉内含的圆
int i,j,k;
bool mark[]={};
for(i=;i<n;i++){
for(int j=;j<n;j++){
if(i!=j&&!mark[j]){
if((c[i]==c[j])||inner(c[j],c[i])) break;
}
}
if(j<n) mark[i]=;
}
for(i=;i<n;i++){
if(!mark[i]){
c[k++]=c[i];
}
}
n=k;
} double areaarc(double th,double r){///半径为r的圆,弧度为th,对应的弓形的面积
return 0.5*r*r*(th-sin(th));
} void getarea(){
memset(ans,,sizeof(ans));
vector<pair<double,int> >v;
for(int i=;i<n;i++){
v.clear();
v.push_back(make_pair(-PI,));
v.push_back(make_pair(PI,-));
for(int j=;j<n;j++){
if(i!=j){
Point q=(c[j].p-c[i].p);
double ab=q.len(),ac=c[i].r,bc=c[j].r;
if(sgn(ab+ac-bc)<=){
v.push_back(make_pair(-PI,));
v.push_back(make_pair(PI,-));
continue;
}
if(sgn(ab+bc-ac)<=)continue;
if(sgn(ab-ac-bc)>) continue;
double th=atan2(q.y,q.x),fai=acos((ac*ac+ab*ab-bc*bc)/(2.0*ac*ab));
double a0=th-fai;
if(sgn(a0+PI)<) a0+=*PI;
double a1=th+fai;
if(sgn(a1-PI)>) a1-=*PI;
if(sgn(a0-a1)>){
v.push_back(make_pair(a0,));
v.push_back(make_pair(PI,-));
v.push_back(make_pair(-PI,));
v.push_back(make_pair(a1,-));
}
else{
v.push_back(make_pair(a0,));
v.push_back(make_pair(a1,-));
}
}
sort(v.begin(),v.end());
int cur=;
for(int j=;j<v.size();j++){
if(cur&&sgn(v[j].first-pre[cur])){
ans[cur]+=areaarc(v[j].first-pre[cur],c[i].r);
ans[cur]+=0.5*(Point(c[i].p.x+c[i].r*cos(pre[cur]),c[i].p.y+c[i].r*sin(pre[cur]))^Point(c[i].p.x+c[i].r*cos(v[j].first),c[i].p.y+c[i].r*sin(v[j].first)));
}
cur+=v[j].second;
pre[cur]=v[j].first;
}
}
}
for(int i=;i<n;i++){
ans[i]-=ans[i+];
}
}
}; bool Check(Line a,Line b){
if(sgn((a.s-a.e)^(b.s-a.e))*sgn((a.s-a.e)^(b.e-a.e))>) return false;
if(sgn((b.s-b.e)^(a.s-b.e))*sgn((b.s-b.e)^(a.e-b.e))>) return false;
if(sgn(max(a.s.x,a.e.x)-min(b.s.x,b.e.x))>=&&sgn(max(b.s.x,b.e.x)-min(a.s.x,a.e.x))>=
&&sgn(max(a.s.y,a.e.y)-min(b.s.y,b.e.y))>=&&sgn(max(b.s.y,b.e.y)-min(a.s.y,a.e.y))>=)
return true;
else return false;
} Line L[]; int main(){
int t;
scanf("%d",&t);
Point p;
for(int Case=;Case<=t;Case++){
double r;
int n;
scanf("%lf %d",&r,&n);
polygon poly;
halfplane hp;
halfplanes hps;
hps.n=;
hp.s.x=r,hp.s.y=-r,hp.e.x=r,hp.e.y=r,hps.push(hp);
hp.s.x=r,hp.s.y=r,hp.e.x=-r,hp.e.y=r,hps.push(hp);
hp.s.x=-r,hp.s.y=r,hp.e.x=-r,hp.e.y=-r,hps.push(hp);
hp.s.x=-r,hp.s.y=-r,hp.e.x=r,hp.e.y=-r,hps.push(hp);
for(int i=;i<=n;i++){
L[i].input();
}
p.input();
for(int i=;i<=n;i++){
if(cross(L[i].s,p,L[i].e)>=){
swap(L[i].s,L[i].e);
}
hp.s=L[i].s,hp.e=L[i].e;
hps.push(hp);
}
if(hps.halfplaneinsert()){
hps.getconvex(poly);
}
circle c(,,r);
double ans1=c.area();
double ans2=poly.areacircle(c);
printf("Case %d: %.5f%%\n",Case,ans2*/ans1);
}
return ;
}
/* 5 1
-5 0 5 3
0 0 5 2
-5 0 5 3
-5 0 5 -3
0 0 5 2
-5 0 5 3
-5 0 5 -3
0 4.9 5 2
-5 0 5 3
-5 0 5 -3
0 -4.9 1.00 2
-1.00 0.00 1.00 0.00
0.00 -1.00 0.00 1.00
0.50 0.50 1.00 1
-1.00 0.00 1.00 0.00
0.50 0.50 */
Harry Potter and J.K.Rowling(半平面交+圆和矩形交)的更多相关文章
- hdu 3982 Harry Potter and J.K.Rowling (半平面交 + 圆与多边形交)
Problem - 3982 题意就是给出一个圆心在原点半径为R的圆形蛋糕,上面有一个cherry,对蛋糕切若干刀,最后要求求出有cherry的那块的面积占整个蛋糕的多少. 做法显而易见,就是一个半平 ...
- HDU - 3982:Harry Potter and J.K.Rowling(半平面交+圆与多边形求交)(WA ing)
pro:给定一枚蛋糕,蛋糕上某个位置有个草莓,寿星在上面切了N刀,最后寿星会吃含有草莓的那一块蛋糕,问他的蛋糕占总蛋糕的面积比. sol:显然需要半平面交求含有蛋糕的那一块,然后有圆弧,不太方便求交. ...
- J.K.罗琳女士---《失败的好处和想象的重要性》
目录 sohu ruanyifeng web sohu http://www.sohu.com/a/166181502_467718 <哈利波特>的作者J.K.罗琳女士在出席一次哈佛大学的 ...
- 今天遇到的面试题for(j=0,i=0;j<6,i<10;j++,i++) { k=i+j; } k 值最后是多少?
for(j=0,i=0;j<6,i<10;j++,i++) { k=i+j; } k 值最后是多少? <script type="text/javascript" ...
- 有两个序列A和B,A=(a1,a2,...,ak),B=(b1,b2,...,bk),A和B都按升序排列。对于1<=i,j<=k,求k个最小的(ai+bj)。要求算法尽量高效。
有两个序列A和B,A=(a1,a2,...,ak),B=(b1,b2,...,bk),A和B都按升序排列.对于1<=i,j<=k,求k个最小的(ai+bj).要求算法尽量高效. int * ...
- c代码,输出i,j,k互不相同的三位数
#include <stdio.h> int main() { int i,j,k; printf("\n"); for(i=1;i<5;i++){ for(j= ...
- 树链剖分-点的分治(dis[i]+dis[j]==k的点对数量)
poj2114 Boatherds Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1195 Accepted: 387 ...
- Codeforces 918 括号匹配 SGdp[i][j][k]
A B C #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) ...
- python中数组切片[:,i] [i:j:k] [:-i] [i,j,:k]
逗号","分隔各个维度,":"表示各个维度内的切片,只有:表示取这个维度的全部值,举例说明如下 1 1.二维数组 2 3 X[:,0]取所有行的第0个数据,第二 ...
随机推荐
- 2016310Exp5 MSF基础应用
1. 实践目标 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 1.1一个主动攻击实践,如ms08_067; (1分) 1.2 一个针对浏览器的攻击, ...
- java核心-多线程-Java多线程编程涉及到包、类
Java有关多线程编程设计的类主要涉及两个包java.lang和java.util.concurrent两个包 java.lang包,主要是线程基础类 <1>Thread <2> ...
- 电脑忘记WiFi密码了,但又想知道,该怎么办?
如何查看电脑已经连过的WiFi的密码? 你有没有遇到这样的情况,电脑之前连过的WiFi,正好手机也想连此WiFi,但是忘记密码了,没有WiFi的手机怎么能叫手机呢?.下面我们来看看如何查看已连接过的W ...
- dpdk环境配置
1.配置流程 [1]修改/boot/grub2/grub.cfg,添加下列标记的配置项. linux16 /vmlinuz--.el7.x86_64 root=/dev/mapper/centos-r ...
- Vue 使用axios获取数据
axios 的使用 1.安装 cnpm install axios --save 2.哪里用哪里引入axios <script> import Axios from 'axios' ...
- Linq to SQL -- Insert、Update、Delete
Insert/Update/Delete操作 插入(Insert) 1.简单形式 说明:new一个对象,使用InsertOnSubmit方法将其加入到对应的集合中,使用SubmitChanges()提 ...
- postman引用外部文件中的变量和数据
接口参数显示: 点击collections下文件夹test0424右边的箭头,点击run按钮: DataFile导入txt文件: 预览文件数据: 运行,成功:
- redis基本数据结构
redis5中数据类型
- python threading 用法
python 多线程传参有点奇怪记录一下 import thread sql1 = 'select 1' sql2 = 'select 2' def run(sql): print sql # 说明 ...
- 在IDEA中设置命令行参数