标签:src 计算几何 tmp event lap 坐标 include continue 方法
1 #include<bits/stdc++.h> 2 #define db double 3 #define eps 1e-6 4 using namespace std; 5 const int N=1<<9; 6 int n,m,cnt,tmp; 7 int dcmp(db x){return fabs(x)<=eps?0:x<0?-1:1;} 8 struct point{ 9 db x,y; 10 point(db _x=0,db _y=0):x(_x),y(_y){}; 11 point operator +(const point&A)const{return point(x+A.x,y+A.y);} 12 point operator -(const point&A)const{return point(x-A.x,y-A.y);} 13 point operator *(const db&a)const{return point(x*a,y*a);} 14 db operator *(const point&A)const{return x*A.x+y*A.y;} 15 db operator ^(const point&A)const{return x*A.y-y*A.x;} 16 }p1[N],p2[N],q[N],qq[N]; 17 bool onleft(point A,point B,point C){ 18 return dcmp((C-B)^(A-B))>0; 19 } 20 point rev(point A,point B,point C){ 21 point D = C - B; 22 db l2 = D*D; 23 D = B + D*((A-B)*D/l2); 24 return D*2 - A; 25 } 26 int main(){ 27 #ifndef ONLINE_JUDGE 28 freopen("bzoj1074.in","r",stdin); 29 freopen("bzoj1074.out","w",stdout); 30 #endif 31 scanf("%d", &n); 32 for(int i=1;i<=n;i++)scanf("%lf%lf%lf%lf", &p1[i].x, &p1[i].y, &p2[i].x, &p2[i].y); 33 scanf("%d", &m); 34 for(int i=1;i<=m;i++){ 35 cnt=1;scanf("%lf%lf", &q[1].x, &q[1].y); 36 for(int j=n;j;j--){ 37 tmp=0; 38 for(int k=1;k<=cnt;k++)if(onleft(q[k],p1[j],p2[j])){ 39 qq[++tmp] = q[k]; 40 qq[++tmp] = rev(q[k],p1[j],p2[j]); 41 } 42 cnt=tmp; 43 if(!cnt)break; 44 for(int k=1;k<=cnt;k++)q[k]=qq[k]; 45 } 46 int ans=0; 47 // puts(""); 48 for(int j=1;j<=cnt;j++){ 49 // printf("%.2f %.2lf\n",q[j].x, q[j].y); 50 if(dcmp(q[j].x)>0&&dcmp(q[j].y)>0&&dcmp(100-q[j].x)>0&&dcmp(100-q[j].y)>0){ 51 ans ++; 52 } 53 } 54 printf("%d\n",ans); 55 } 56 return 0; 57 }
1 #include<bits/stdc++.h> 2 #define db double 3 #define il inline 4 using namespace std; 5 const int N=110; 6 int n,k; 7 db R,t[N][N]; 8 struct point{ 9 db x,y; 10 point(db _x=0,db _y=0):x(_x),y(_y){}; 11 point operator +(const point&A)const{return point(x+A.x,y+A.y);} 12 point operator -(const point&A)const{return point(x-A.x,y-A.y);} 13 point operator *(const db&a)const{return point(x*a,y*a);} 14 db operator *(const point&A)const{return x*A.x+y*A.y;} 15 db operator ^(const point&A)const{return x*A.y-y*A.x;} 16 }O,p[N][N],v[N][N]; 17 il db cal(db a,db b,db c){return ( -b + sqrt(b*b-4*a*c) ) / a / 2; } 18 il db len(point A){return sqrt(A*A);} 19 il db solve(int i,int j,int k1,int k2,db tl,db tr){ 20 point v1 = v[i][k1], v2 = v[j][k2]; 21 point p1 = p[i][k1] + v1 * (tl - t[i][k1]); 22 point p2 = p[j][k2] + v2 * (tl - t[j][k2]); 23 point tv = v1-v2, tp = p1-p2; tr-=tl; 24 db a=tv*tv,b=tv*tp*2,d=-b/a/2; 25 if(fabs(a)<1e-9)return b > 0 ? len(tv*tr+tp) : len(tv*tl+tp); 26 else { 27 d = max(0.0, min(tr, d)); 28 return len(tv*d+tp); 29 } 30 } 31 int main(){ 32 #ifndef ONLINE_JUDGE 33 freopen("bzoj1094.in", "r", stdin); 34 freopen("bzoj1094.out","w",stdout); 35 #endif 36 scanf("%lf%lf%lf",&O.x,&O.y,&R); 37 scanf("%d%d",&n,&k); 38 for(int i=1;i<=n;i++){ 39 scanf("%lf%lf%lf%lf",&p[i][0].x,&p[i][0].y,&v[i][0].x,&v[i][0].y); 40 for(int j=1;j<=k+1;j++){ 41 point tp = p[i][j-1] - O, tv = v[i][j-1]; 42 db tx = cal(tv*tv, tp*tv*2, tp*tp-R*R); 43 t[i][j] = t[i][j-1] + tx; 44 p[i][j] = p[i][j-1] + tv*tx; 45 point l = O - p[i][j]; swap(l.x,l.y),l.x=-l.x; 46 v[i][j] = l * ((tv*l)/(l*l)) * 2 - tv; 47 } 48 } 49 db ans = 1e18; 50 for(int i=1;i<=n;i++) 51 for(int j=1;j<=n;j++)if(i!=j){ 52 int k1=0,k2=0; 53 while(k1<=k&&k2<=k){ 54 ans = min(ans, solve(i, j, k1, k2, max(t[i][k1],t[j][k2]), min(t[i][k1+1],t[j][k2+1]))); 55 if(t[i][k1+1]<t[j][k2+1])k1++;else k2++; 56 } 57 } 58 printf("%.3lf\n",ans); 59 return 0; 60 }
1 #include<bits/stdc++.h> 2 #define db double 3 #define eps 1e-9 4 using namespace std; 5 const int N=1010; 6 const db pi = acos(-1); 7 int n,tot1[N],tot2[N],vis[N]; 8 db sub2[N][N<<2],cnt[N<<2]; 9 struct point{ 10 db x,y; 11 point(db _x=0,db _y=0):x(_x),y(_y){}; 12 point operator +(const point&A)const{return point(x+A.x,y+A.y);} 13 point operator -(const point&A)const{return point(x-A.x,y-A.y);} 14 db operator *(const point&A)const{return x*A.x+y*A.y;} 15 db operator ^(const point&A)const{return x*A.y-y*A.x;} 16 point operator *(const db&a)const{return point(x*a,y*a);} 17 }sub1[N][N<<2]; 18 struct circle{point o;db r;}c[N]; 19 int dcmp(db x){return fabs(x)<eps?0:x<0?-1:1;} 20 db len(point A){return sqrt(A*A);} 21 point rotate(point A,db cos,db sin){return point(A.x*cos-A.y*sin, A.y*cos+A.x*sin);} 22 void ins(int i,point p1,point p2){ 23 db l = atan2(p1.y,p1.x), r = atan2(p2.y,p2.x); 24 sub2[i][++tot2[i]] = l; 25 sub2[i][++tot2[i]] = r; 26 if(dcmp(l-r)>0){ 27 sub1[i][++tot1[i]]=point(-pi,r); 28 sub1[i][++tot1[i]]=point(l,pi); 29 }else sub1[i][++tot1[i]]=point(l,r); 30 } 31 void solve(int i,int j){ 32 if(dcmp(c[i].r-c[j].r)>0)swap(i,j); 33 point td = c[j].o - c[i].o,p0,p1,p2; 34 db d = len(td), r1=c[i].r, r2=c[j].r; 35 if(dcmp(d-r1-r2)>=0)return ; 36 if(dcmp(d-r2+r1)<=0){if(i<j)vis[i]=1;return ;} 37 db Cos = (td*td + r1*r1 - r2*r2) /d /r1 /2 ; 38 db Sin = sqrt(1-Cos*Cos); 39 p0 = td * (r1/d); 40 p1 = c[i].o + rotate(p0,Cos,-Sin);// 41 p2 = c[i].o + rotate(p0,Cos,Sin); 42 if(i<j)ins(i,p1-c[i].o, p2-c[i].o); 43 else ins(j,p2-c[j].o, p1-c[j].o); 44 } 45 int main(){ 46 freopen("bzoj1043.in","r",stdin); 47 freopen("bzoj1043.out","w",stdout); 48 scanf("%d",&n); 49 for(int i=1;i<=n;i++){ 50 scanf("%lf%lf%lf",&c[i].r,&c[i].o.x,&c[i].o.y); 51 for(int j=i-1;j;j--)solve(j,i); 52 } 53 db ans = 0; 54 for(int i=1;i<=n;i++){ 55 if(vis[i])continue; 56 sub2[i][++tot2[i]]=-pi; 57 sub2[i][++tot2[i]]=pi; 58 sort(sub2[i]+1,sub2[i]+tot2[i]+1); 59 for(int j=1;j<=tot2[i];j++)cnt[j]=0; 60 for(int j=1;j<=tot1[i];j++){ 61 int p1 = lower_bound(sub2[i]+1,sub2[i]+tot2[i]+1,sub1[i][j].x) - sub2[i]; 62 int p2 = lower_bound(sub2[i]+1,sub2[i]+tot2[i]+1,sub1[i][j].y) - sub2[i]; 63 cnt[p1]--,cnt[p2]++; 64 } 65 db all = 0; 66 for(int j=1;j<tot2[i];j++){ 67 cnt[j]+=cnt[j-1]; 68 if(!cnt[j])all += sub2[i][j+1]-sub2[i][j]; 69 } 70 ans += all * c[i].r; 71 } 72 printf("%.3lf\n", ans); 73 }
标签:src 计算几何 tmp event lap 坐标 include continue 方法
原文地址:https://www.cnblogs.com/Paul-Guderian/p/10257528.html