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

Problem Description
In July 31st, last month, the author of the famous novel series J.K.Rowling celebrated her 46th birthday. Many friends gave their best wishes. They gathered together and shared one large beautiful cake.
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.
 
Input
First line has an integer T, indicating the number of test cases.
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.

 
Output
For each test case, in one line output the case number and the percentage the piece with the cherry has of whole original cake, rounded to five fractional digits.
 
Sample Input
1
1.00 2
-1.00 0.00 1.00 0.00
0.00 -1.00 0.00 1.00
0.50 0.50
 
Sample Output
Case 1: 25.00000%

附上测试数据,半平面交模板题

 #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(半平面交+圆和矩形交)的更多相关文章

  1. hdu 3982 Harry Potter and J.K.Rowling (半平面交 + 圆与多边形交)

    Problem - 3982 题意就是给出一个圆心在原点半径为R的圆形蛋糕,上面有一个cherry,对蛋糕切若干刀,最后要求求出有cherry的那块的面积占整个蛋糕的多少. 做法显而易见,就是一个半平 ...

  2. HDU - 3982:Harry Potter and J.K.Rowling(半平面交+圆与多边形求交)(WA ing)

    pro:给定一枚蛋糕,蛋糕上某个位置有个草莓,寿星在上面切了N刀,最后寿星会吃含有草莓的那一块蛋糕,问他的蛋糕占总蛋糕的面积比. sol:显然需要半平面交求含有蛋糕的那一块,然后有圆弧,不太方便求交. ...

  3. J.K.罗琳女士---《失败的好处和想象的重要性》

    目录 sohu ruanyifeng web sohu http://www.sohu.com/a/166181502_467718 <哈利波特>的作者J.K.罗琳女士在出席一次哈佛大学的 ...

  4. 今天遇到的面试题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" ...

  5. 有两个序列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 * ...

  6. c代码,输出i,j,k互不相同的三位数

    #include <stdio.h> int main() { int i,j,k; printf("\n"); for(i=1;i<5;i++){ for(j= ...

  7. 树链剖分-点的分治(dis[i]+dis[j]==k的点对数量)

    poj2114 Boatherds Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1195   Accepted: 387 ...

  8. 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)) ...

  9. python中数组切片[:,i] [i:j:k] [:-i] [i,j,:k]

    逗号","分隔各个维度,":"表示各个维度内的切片,只有:表示取这个维度的全部值,举例说明如下 1 1.二维数组 2 3 X[:,0]取所有行的第0个数据,第二 ...

随机推荐

  1. python之路——22

    学习内容 1.初识面向对象 类:抽象的,模子 对象:具体的,根据类规范 代码精简,修改方便,属性规范2.对象 查看属性 调用方法 __dict__,增删改查,通过字典语法进行3.类名 1.实例化 2. ...

  2. mybatis 日志的使用以及设计

    1.为什么要配置mybtis的logger? mybatis自己设计以及实现了org.apache.ibatis.logging.Log接口. Mybatis为了避免对第三方的日志包存在强依赖,内部的 ...

  3. 安装部署Kafka集群

    kafka是一个开源的分布式消息订阅系统(消息中间件) 安装过程 1.下载kafka_2.11-0.10.1.0.gz(ps:千万不要下错了,博主就是下到了src文件上去了,kafka中的zookee ...

  4. 二叉搜索树(BST)学习笔记

    BST调了一天,最后遍历参数错了,没药救了-- 本文所有代码均使用数组+结构体,不使用指针! 前言--BFS是啥 BST 二叉搜索树是基于二叉树的一种树,一种特殊的二叉树. 二叉搜索树要么是一颗空树, ...

  5. TMS320F28335系列芯片地址映射表

    本表非官方资料,纯属个人学习笔记,欢迎补充 本表非官方资料,纯属个人学习笔记,欢迎补充 本表非官方资料,纯属个人学习笔记,欢迎补充 开始地址 长度 名称 物理器件 程序 数据 只读 Protected ...

  6. flutter 列表展示

    内容: 1.列表展示 2.轮播图 3.其他 本次的内容也是在上一节的基础上进行操作 我们就搞这个story模块. 目录: story.dart  story主页面 import 'package:fl ...

  7. scrapy爬去京东书籍信息

    # -*- coding: utf-8 -*- import scrapy import urllib import json from copy import deepcopy class JdSp ...

  8. python———day03

    一.字符串格式化输出: 占位符    %s(字符串) %d(整数) %f(浮点数,约等于小数) name = input("Name:") age = input("Ag ...

  9. leetcode1035

    class Solution: def maxUncrossedLines(self, A: 'List[int]', B: 'List[int]') -> int: m = len(A) n ...

  10. nodeJs 使用 express-http-proxy 转发请求

    开发过程中经常需要用到 nodeJs做转发层 使用express配合 express-http-proxy 可以轻松的完成转发 使用过程: 安装 express-http-proxy npm inst ...