HDU 5033 Building

题意:

城市看做二维平面,建筑看做x轴上某个位置为端点的竖着的线段,(xi,hi)表示在x轴xi位置有个高为hi的建筑(线段)。有多次询问,每次问人在某个平地上(x,0)能看到天空的角度。

维护建筑物形成的凸下降曲线,每次删除不符合条件的点。再反过来求一遍就可以了。

也就是相邻两建筑顶(xi,hi)的连线的斜率的绝对值上升的单调栈。



Building

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 922    Accepted Submission(s): 260
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.
 

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).
 

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
2014 ACM/ICPC Asia Regional Beijing Online



#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100100 << 2;
const double PI = acos(-1.0);
struct Node
{
    double x, h;
    int id;
    bool operator<(Node b) const { return x < b.x; }
}node[N];
Node S[N];
double ans[N];

bool check(Node a, Node b, Node c)
{
    if(c.h<0) c.h=0;
    return (a.h-b.h) * (c.x-b.x) >= (b.x-a.x) * (b.h-c.h);
}
double getAngle(Node a, Node b)
{
    return atan((b.x-a.x)/a.h);
}
int n,Q;
void get()
{
    int top = 0;
    for(int i=0;i<n+Q;i++)
    {
        if(node[i].h<0)
        {
            while(top>=2 && check(S[top-1], S[top], node[i])) top--;
            ans[node[i].id] += getAngle(S[top], node[i]);
        }
        else {
            while(top && S[top].h <= node[i].h) top--;
            while(top>=2 && check(S[top-1], S[top], node[i])) top--;
            S[++top] = node[i];
        }
    }
}
int main()
{
    int re; cin>>re;  int ca=1;
    while(re--)
    {
        cin>>n;
        for(int i=0;i<n;i++) scanf("%lf%lf", &node[i].x, &node[i].h);
        cin>>Q;
        for(int i=n;i<n+Q;i++) scanf("%lf", &node[i].x), node[i].h = -1, node[i].id = i-n;

        memset(ans,0,sizeof ans);
        sort(node, node+n+Q);
        get();

        reverse(node, node+n+Q);
        for(int i=0;i<n+Q;i++) node[i].x = 1e9 - node[i].x;
        get();

        printf("Case #%d:\n", ca++);
        for(int i=0;i<Q;i++) printf("%.9f\n", ans[i] * 180 / PI);
    }
}


Building

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 922    Accepted Submission(s): 260
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.
 

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).
 

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
2014 ACM/ICPC Asia Regional Beijing Online

你可能感兴趣的:(HDU 5033 Building)