pro:现在在X轴上有N个摩天大楼,以及Q个人,人和大楼的坐标各不相同,保证每个人左边和右边都有楼,问每个人能看到天空的角度大小。
sol:不难想到就是维护凸包,此题就是让你模拟斜率优化,此处没有斜率来做,用几何写的。。。。
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int maxn=200010; const double pi=acos(-1.0); struct in{ double x,h; int id; }s[maxn]; struct point{ double x,y; point(){} point(double xx,double yy):x(xx),y(yy){} }; double det(point a,point b){ return a.x*b.y-a.y*b.x;} double dot(point a,point b){ return a.x*b.x+a.y*b.y;} bool cmp(in w,in v){ return w.x<v.x;} double ans[maxn]; int q[maxn],top; void solve(int N) { sort(s+1,s+N+1,cmp); top=0; rep(i,1,N){ if(s[i].id){ while(top>1&&atan2(s[q[top]].h-s[q[top-1]].h,s[q[top]].x-s[q[top-1]].x) <atan2(-s[q[top]].h,s[i].x-s[q[top]].x)) top--; point T=point(s[q[top]].h,s[q[top]].x-s[i].x); ans[s[i].id]+=asin(fabs(det(point(0,-1),T))/sqrt(dot(T,T))); } else { while(top&&s[q[top]].h<=s[i].h) top--; while(top>1&&atan2(s[q[top]].h-s[q[top-1]].h,s[q[top]].x-s[q[top-1]].x) <atan2(s[i].h-s[q[top]].h,s[i].x-s[q[top]].x)) top--; q[++top]=i; } } } int main() { int T,N,Q,C=0; scanf("%d",&T); while(T--){ scanf("%d",&N); rep(i,1,N){ scanf("%lf%lf",&s[i].x,&s[i].h); s[i].id=0; } scanf("%d",&Q); rep(i,1,Q){ scanf("%lf",&s[N+i].x); s[N+i].id=i,ans[i]=0; s[N+i].h=0; } solve(N+Q); rep(i,1,N+Q) s[i].x=-s[i].x; solve(N+Q); printf("Case #%d: ",++C); rep(i,1,Q) printf("%.10lf ",180-180/pi*ans[i]); } return 0; }