3 3 1 2 2 1 5 1 1 4 3 1 3 2 2 5 1 1 4 3 1 4 2 3 5 1 1 4
Case #1: 101.3099324740 Case #2: 90.0000000000 Case #3: 78.6900675260
#include<algorithm> #include<iostream> #include<string.h> #include<stdio.h> #include<math.h> using namespace std; const int INF=0x3f3f3f3f; const double PI=acos(-1.0); const int maxn=100010; typedef long long ll; struct node { double x,y; } bd[maxn],q[maxn],qu[maxn],le[maxn],ri[maxn]; int head,tail; bool cmp(node a,node b) { return a.x<b.x; } double ans[maxn]; int main() { int t,cas=1,n,m,i,j,p; double x1,y1,x2,y2,per=180/PI; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf%lf",&bd[i].x,&bd[i].y); sort(bd,bd+n,cmp); scanf("%d",&m); for(i=0;i<m;i++) scanf("%lf",&qu[i].x),qu[i].y=i; sort(qu,qu+m,cmp); head=tail=j=0; for(i=0;i<m;i++) { for(;j<n&&bd[j].x<qu[i].x;j++) { while(tail-head>0&&bd[j].y>=q[tail-1].y) tail--; while(tail-head>=2) { p=tail-1; x2=bd[j].x-q[p].x; y2=bd[j].y-q[p].y; x1=q[p].x-q[p-1].x; y1=q[p].y-q[p-1].y; if(x1*y2>=x2*y1) tail--; else break; } q[tail].x=bd[j].x; q[tail++].y=bd[j].y; } if(tail-head==0) le[i].x=qu[i].x-1,le[i].y=0; else { while(tail-head>=2) { p=tail-1; x2=qu[i].x-q[p].x; y2=-q[p].y; x1=qu[i].x-q[p-1].x; y1=-q[p-1].y; if(x2*y1<=x1*y2) tail--; else break; } le[i].x=q[tail-1].x; le[i].y=q[tail-1].y; } } head=tail=0,j=n-1; for(i=m-1;i>=0;i--) { for(;j>=0&&bd[j].x>qu[i].x;j--) { while(tail-head>0&&bd[j].y>=q[tail-1].y) tail--; while(tail-head>=2) { p=tail-1; x2=bd[j].x-q[p].x; y2=bd[j].y-q[p].y; x1=q[p].x-q[p-1].x; y1=q[p].y-q[p-1].y; if(x2*y1>=x1*y2) tail--; else break; } q[tail].x=bd[j].x; q[tail++].y=bd[j].y; } if(tail-head==0) ri[i].x=qu[i].x+1,ri[i].y=0; else { while(tail-head>=2) { p=tail-1; x2=qu[i].x-q[p].x; y2=-q[p].y; x1=qu[i].x-q[p-1].x; y1=-q[p-1].y; if(x1*y2<=x2*y1) tail--; else break; } ri[i].x=q[tail-1].x; ri[i].y=q[tail-1].y; } } for(i=0;i<m;i++) { x1=le[i].x-qu[i].x; y1=le[i].y; x2=ri[i].x-qu[i].x; y2=ri[i].y; ans[int(qu[i].y)]=per*acos((x1*x2+y1*y2)/(sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2))); } printf("Case #%d:\n",cas++); for(i=0;i<m;i++) printf("%.10f\n",ans[i]); } return 0; }
原文地址:http://blog.csdn.net/bossup/article/details/39529545