标签:erro math for 输入 ase its imp sam 都对
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; const int maxn=1e5+5; const double PI=acos(-1); struct Node{ double x; double y; int L,R,id; }a[2*maxn]; int top,s[maxn]; bool cmp(const Node s1,const Node s2) { return s1.x<s2.x; } bool cmp2(const Node s1,const Node s2) { return s1.id<s2.id; } double cal2(double x,double y) { //cout<<"H:"<<x<<" "<<y<<endl; return atan(y/x); } int main() { ///cout << "Hello world!" << endl; int T,Case=1; cin>>T; while(T--) { printf("Case #%d:\n",Case++); int N; scanf("%d",&N); for(int i=1;i<=N;i++) scanf("%lf%lf",&a[i].x,&a[i].y),a[i].id=i; int Q; scanf("%d",&Q); for(int i=N+1;i<=N+Q;i++) scanf("%lf",&a[i].x),a[i].y=0,a[i].id=i; sort(a+1,a+N+Q+1,cmp); ///for(int i=1;i<=N+Q;i++) cout<<a[i].id<<" "<<a[i].x<<" "<<a[i].y<<endl; top=0; s[0]=1; for(int i=2;i<=N+Q;i++) { while(1) { if(top<1) break; double x1=a[s[top]].x-a[s[top-1]].x; double y1=a[s[top]].y-a[s[top-1]].y; //double f1=cal(a[s[top-1]].x, a[s[top-1]].y, a[s[top]].x, a[s[top]].y); double x2=a[i].x-a[s[top]].x; double y2=a[i].y-a[s[top]].y; //double f2=cal(a[s[top]].x, a[s[top]].y, a[i].x, a[i].y); if(y1*x2>y2*x1) break; top--; } if(a[i].id>N) a[i].L=a[s[top]].id;//,cout<<"top1 "<<top<<" "<<s[top]<<" "<<a[s[top]].id<<endl; s[++top]=i; } top=0; s[0]=N+Q; for(int i=N+Q-1;i>=1;i--) { while(1) { if(top<1) break; double x1=a[s[top-1]].x-a[s[top]].x; double y1=a[s[top-1]].y-a[s[top]].y; //double f1=cal(a[s[top-1]].x, a[s[top-1]].y, a[s[top]].x, a[s[top]].y); double x2=a[s[top]].x-a[i].x; double y2=a[s[top]].y-a[i].y; //double f2=cal(a[s[top]].x, a[s[top]].y, a[i].x, a[i].y); if(y1*x2<y2*x1) break; top--; } if(a[i].id>N) a[i].R=a[s[top]].id;//,cout<<"top2 "<<top<<" "<<s[top]<<" "<<a[s[top]].id<<endl; s[++top]=i; } sort(a+1,a+N+Q+1,cmp2); for(int i=N+1;i<=N+Q;i++) { //cout<<"--->"<<a[i].L<<" "<<a[i].R<<endl; double ans=PI; int k=a[i].L; ans-=cal2(a[i].x-a[k].x,a[k].y); k=a[i].R; ans-=cal2(a[k].x-a[i].x,a[k].y); printf("%.10f\n",ans*180/PI); } } return 0; }
标签:erro math for 输入 ase its imp sam 都对
原文地址:http://www.cnblogs.com/chen9510/p/7246889.html