Building
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 70 Accepted Submission(s): 4
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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <iomanip>
#include <cassert>
using namespace std;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define ff(i, n) for(int i=0;i<(n);i++)
#define fff(i, n, m) for(int i=(n);i<=(m);i++)
#define dff(i, n, m) for(int i=(n);i>=(m);i--)
#define bit(n) (1LL<<(n))
typedef long long LL;
typedef unsigned long long ULL;
void work();
int main()
{
#ifdef ACM
freopen("in.txt", "r", stdin);
#endif // ACM
work();
}
void nextInt(int & x)
{
char ch;
while(ch = getchar(), isdigit(ch) == false);
x = 0;
while(x = 10 * x + ch - '0', ch = getchar(), isdigit(ch) == true);
}
/*****************************************华丽分割线**********************************************/
const double pi = acos(-1.0);
double ans[111111];
struct Node
{
int x;
int h;
bool operator<(const Node & cmp) const
{
return x < cmp.x;
}
} node[222222];
Node stk[111111];
bool check(Node & a, Node & b, Node c)
{
if(c.h <= 0) c.h = 0;
return (LL)(a.h - c.h) * (c.x - b.x) >= (LL)(b.h - c.h) * (c.x - a.x);
}
double getAngle(Node a, Node b)
{
return atan((double)(b.x-a.x)/(double)(a.h));
}
int n, q;
void get()
{
int top = 0;
ff(i, n + q)
{
if(node[i].h <= 0)
{
while (top >= 2 && check(stk[top-2], stk[top-1], node[i])) top -- ;
ans[-node[i].h] += getAngle(stk[top-1], node[i]);
}
else
{
while (top && stk[top-1].h <= node[i].h) top -- ;
while (top >= 2 && check(stk[top-2], stk[top-1], node[i])) top -- ;
stk[top++] = node[i];
}
}
}
void work()
{
int T;
scanf("%d", &T);
fff(cas, 1, T)
{
scanf("%d", &n);
ff(i, n)
scanf("%d%d", &node[i].x, &node[i].h);
scanf("%d", &q);
ff(i, q)
scanf("%d", &node[i+n].x), node[i+n].h = -i;
memset(ans, 0, sizeof(ans));
sort(node, node + n + q);
get();
reverse(node, node + n + q);
ff(i, n + q) node[i].x = 10000000 - node[i].x;
get();
printf("Case #%d:\n", cas);
ff(i, q) printf("%.10lf\n", ans[i] * 180.0 / pi);
}
}