Building
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1162 Accepted Submission(s): 331
Special Judge
Problem Description
Once upon a time Matt went to a small town. The town was so small and narrow that he can regard the town as a pivot. There were some skyscrapers in the town, each located at position x
i with its height h
i. All skyscrapers located in different place. The skyscrapers had no width, to make it simple. As the skyscrapers were so high, Matt could hardly see the sky.Given the position Matt was at, he wanted to know how large the angle range was where he could see the sky. Assume that Matt's height is 0. It's guaranteed that for each query, there is at least one building on both Matt's left and right, and no building locate at his position.
Input
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.
Each test case begins with a number N(1<=N<=10^5), the number of buildings.
In the following N lines, each line contains two numbers, x i(1<=x i<=10^7) and h i(1<=h i<=10^7).
After that, there's a number Q(1<=Q<=10^5) for the number of queries.
In the following Q lines, each line contains one number q i, which is the position Matt was at.
Each test case begins with a number N(1<=N<=10^5), the number of buildings.
In the following N lines, each line contains two numbers, x i(1<=x i<=10^7) and h i(1<=h i<=10^7).
After that, there's a number Q(1<=Q<=10^5) for the number of queries.
In the following Q lines, each line contains one number q i, which is the position Matt was at.
Output
For each test case, first output one line "Case #x:", where x is the case number (starting from 1).
Then for each query, you should output the angle range Matt could see the sky in degrees. The relative error of the answer should be no more than 10^(-4).
Then for each query, you should output the angle range Matt could see the sky in degrees. The relative error of the answer should be no more than 10^(-4).
Sample Input
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
Sample Output
Case #1: 101.3099324740 Case #2: 90.0000000000 Case #3: 78.6900675260
Source
维护单调栈,始终保留斜率最大的,纸上画画就清楚了
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define DWN(i,h,l) for(int i=(h);i>=(l);--i)
#define CLR(vis,pos) memset(vis,pos,sizeof(vis))
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LINF 1000000000000000000LL
#define eps 1e-8
typedef long long ll;
typedef double PointType;
struct point{
PointType x,y;
point(PointType x=0,PointType y=0):x(x),y(y) {}
};
typedef point Vector ;
int dcmp(double x){
if(fabs(x) < eps) return 0;else return x<0 ?-1:1;
}
Vector operator + (Vector A , Vector B){
return Vector(A.x + B.x , A.y + B.y);
}
Vector operator - (point A , point B){
return Vector(A.x - B.x , A.y - B.y);
}
Vector operator * (Vector A , double p){
return Vector(A.x * p, A.y * p);
}
Vector operator / (Vector A , double p){
return Vector(A.x / p, A.y / p);
}
bool operator < (const point& a, const point& b){
return a.x<b.x||(a.x==b.x && a.y<b.y);
}
bool operator == (const point& a, const point& b){
return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}
double Dot(Vector A , Vector B){
return A.x*B.x+A.y*B.y;
}
double Length(Vector A){
return sqrt(Dot(A,A));
}
double Cross(Vector A , Vector B){
return A.x*B.y - A.y*B.x;
}
double Angle(Vector A , Vector B){
return acos(Dot(A, B) / Length(A) / Length(B));
}
const int maxn=2*1e5+100;
point a[maxn];
double ans[maxn];
int n,q;
point stk[maxn];
bool check(point &a,point &b,point c){
if(c.y<=0) c.y=0;
return (a.y-c.y)*(c.x-b.x)>=(b.y-c.y)*(c.x-a.x);
}
double get_angle(point a,point b){
return atan((double)(b.x-a.x)/(double)(a.y));
}
void work(){
int top=0;
REP(i,n+q){
if(a[i].y<=0){
while(top>=2 && check(stk[top-2],stk[top-1],a[i])) top--;
ans[-(int)a[i].y] += get_angle(stk[top-1],a[i]);
}
else{
while(top && stk[top-1].y<=a[i].y) top--;
while(top>=2 && check(stk[top-2],stk[top-1],a[i])) top--;
stk[top++]=a[i];
}
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int _;
cin>>_;
REP(cas,_){
scanf("%d",&n);
REP(i,n){
scanf("%lf%lf",&a[i].x,&a[i].y);
}
scanf("%d",&q);
REP(i,q){
scanf("%lf",&a[i+n].x);
a[i+n].y=-i;
}
sort(a,a+n+q);
CLR(ans,0);
work();
reverse(a,a+n+q);
REP(i,n+q){
a[i].x=10000000-a[i].x;
}
work();
printf("Case #%d:\n",cas+1);
REP(i,q){
printf("%.10lf\n",ans[i]*180.0/PI);
}
}
return 0;
}