标签:des style blog color io os java ar strong
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1011 Accepted Submission(s): 281
Special Judge
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstdio> using namespace std; typedef long long LL; #define PI acos(-1.0) #define eps 1e-8 const int N = 200100; int n , m ; struct node { double x, y ; node (){}; node operator - (const node &a )const{ node res ;res.x = x - a.x , res.y = y- a.y; return res; } }Q[N],e[N],ch[N]; inline bool cmp1(const node &a ,const node &b ){ return a.x < b.x ;} inline bool cmp2(const node &a ,const node &b ){ return a.y < b.y ;} inline double Cross( node a ,node b ){ return a.x * b.y - a.y * b.x ; } double L[N] , R[N] ; double cal( node a ,node b ){ return max( 0.0, atan( fabs( a.y - b.y ) / fabs( a.x - b.x ) ) * 180.0 / PI ); } void solve() { int top = 0 ; for( int i = 0 ; i < n ; ++ i ) { while( top > 0 && e[i].y >= ch[top-1].y ) top--; while( top > 1 && Cross( ch[ top - 1 ] - ch[ top -2 ] , e[i] - ch[ top - 2 ] ) >= 0 ) top-- ; ch[ top++ ] = e[i]; if( top == 1 ) L[i] = 0 ; else L[i] = cal( ch[top-2] , ch[top-1] ); } top = 0 ; for( int i = n - 1 ; i >= 0 ;--i ){ while( top > 0 && e[i].y >= ch[top-1].y ) top--; while( top > 1 && Cross( ch[ top - 1 ] - ch[ top -2 ] , e[i] - ch[ top - 2 ] ) <= 0 ) top--; ch[ top ++ ] = e[i]; if( top <= 1 ) R[i] = 0; else R[i] = cal(ch[top-2],ch[top-1]); } int tot = 0 ; for(int i = 0 ; i < n ; ++i ){ if( Q[tot].x == e[i].x ){ Q[tot++].x = 180.0 -L[i] -R[i] ; } if(tot == m )break; } } void run() { scanf("%d",&n); for( int i = 0; i < n ; ++i ){ scanf("%lf%lf",&e[i].x, &e[i].y); } scanf("%d",&m); for(int i = 0 ; i < m ; ++i ){ scanf("%lf",&Q[i].x); Q[i].y = i ; e[ n + i ].x = Q[i].x ; e[ n + i ].y = 0 ; } n += m ; sort(Q,Q+m,cmp1); sort(e,e+n,cmp1); solve(); sort(Q,Q+m,cmp2); for( int i = 0 ; i < m ; ++i ){ printf("%.10lf\n",Q[i].x); } } int main() { #ifdef LOCAL freopen("in","r",stdin); #endif int cas = 1 ,_ ; scanf("%d",&_) ; while(_--) { printf("Case #%d:\n",cas++); run(); } return 0; }
标签:des style blog color io os java ar strong
原文地址:http://www.cnblogs.com/YRETSIM/p/3988882.html