Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 288 Accepted Submission(s): 75
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 xi with its height hi. 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, xi(1<=xi<=10^7) and hi(1<=hi<=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 qi, 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
Recommend
hujie | We have carefully selected several similar problems for you: 5041 5040 5039 5038 5037
Total Submission(s): 288 Accepted Submission(s): 75
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 xi with its height hi. 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, xi(1<=xi<=10^7) and hi(1<=hi<=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 qi, 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
Recommend
hujie | We have carefully selected several similar problems for you: 5041 5040 5039 5038 5037
思路:
先把n个点按从x从小到大排序然后把q次询问保存起来,按x从小到大保存起来,并把每个q的原来位置记录下来。。分别算出左边的斜率 和右边的斜率。计算左边的话是维护一个单调递减的单调栈。。n个点入队的顺序是按x从小到大 ,把所有x小于当前询问的点入栈,然后把取栈中与改点构成斜率最大的斜率保存起来计算出角度保存到ans1
右边同理 也是维护一个单调递减栈,不过n个点入队的顺序是从大到小同时q个询问 也是从大到小 最后每个询问的答案就是180 - ans1[i] - ans2[i]
代码:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
double PI = acos(-1.0);
struct point
{
double x,h;
}a[110000];
struct qu
{
double q;
int vis;
}q[110000];
bool cmp1 (point a, point b)
{
return a.x < b.x;
}
bool cmp(qu a, qu b)
{
return a.q < b.q;
}
int t,n,p,b[110000];
double ans1[110000],ans2[110000];
int main()
{
scanf("%d",&t);
int ca = 1;
int i,st,j;
while(t--)
{
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%lf %lf",&a[i].x, &a[i].h);
}
sort(a,a + n,cmp1);
scanf("%d",&p);
for(i = 0; i < p; i++)
{
scanf("%lf",&q[i].q);
q[i].vis = i;
}
sort(q,q + p,cmp);
b[0] = 0;
st = 0;
int end = 1;
for(i = 0; i < p; i++)
{
while (a[end].x < q[i].q)
{
while (a[b[st]].h < a[end].h && st >= 0)
{
st--;
}
b[++st] = end++;
}
double kk = -1111.0;
for(j = st; j >= 0; j--)
{
double k = a[b[j]].h / (q[i].q - a[b[j]].x);
if(k > kk)
{
kk = k;
}
}
ans1[q[i].vis] = 180.0*(atan(kk) / PI);
}
b[0] = n -1;
end = n - 2;
st = 0;
for(i = p -1 ; i >= 0; i--)
{
while (a[end].x > q[i].q)
{
while (a[b[st]].h < a[end].h && st >= 0)
{
st--;
}
b[++st] = end--;
}
double kk = -1111.0;
for(j = st; j >= 0; j--)
{
double k = a[b[j]].h / (-q[i].q + a[b[j]].x);
if(k > kk)
{
kk = k;
}
}
ans2[q[i].vis] = 180.0*(atan(kk) / PI);
}
for(i = 0; i < p; i++)
{
ans1[i] = 180.0 - ans1[i] - ans2[i];
}
printf("Case #%d:\n",ca++);
for(i = 0; i < p; i++)
{
printf("%.10lf\n",ans1[i]);
}
}
return 0;
}