hdu5033Building

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 1724    Accepted Submission(s): 508

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

将所有点打入,用斜率递增或者递减维护一个单调栈两次的过程中统计出每个点的左断点跟右端点,最后扫一次算视角即可

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
struct point
{
	double x,y;
	point(){}
	point(double x,double y)
	{
		this->x=x;
		this->y=y;
	}
	int id;
	bool operator <(point one)const
	{
		return x<one.x;
	}
	point operator -(point one)
	{
		return point(x-one.x,y-one.y);
	}
	double operator *(point one)
	{
		return x*one.y-y*one.x;
	}
}box[int(2e5)+10];
vector<int>sk;
int l[int(2e5)+10],r[int(2e5)+10];
double ans[int(2e5)+10];
const double pi=acos(-1.0);
int main()
{
	int T;
	scanf("%d",&T);
	for(int cs=1;cs<=T;cs++)
	{
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%lf%lf",&box[i].x,&box[i].y);
			box[i].id=-1;
		}
		int m;
		scanf("%d",&m);
		m+=n;
		for(int i=n;i<m;i++)
		{
			scanf("%lf",&box[i].x);
			box[i].y=0;
			box[i].id=i-n;
		}
		sort(box,box+m);
		sk.clear();
		sk.push_back(0);
		for(int i=1;i<m;i++)
		{
			while(sk.size()>=2)
			{
				if(!((box[sk.back()]-box[i])*(box[sk[sk.size()-2]]-box[i])<0))
					break;
				sk.pop_back();
			}
			l[i]=sk.back();
			sk.push_back(i);
		}
		sk.clear();
		sk.push_back(m-1);
		for(int i=m-2;i>-1;i--)
		{
			while(sk.size()>=2)
			{
				if(!((box[sk.back()]-box[i])*(box[sk[sk.size()-2]]-box[i])>0))
					break;
				sk.pop_back();
			}
			r[i]=sk.back();
			sk.push_back(i);
		}
		for(int i=0;i<m;i++)
		{
			if(box[i].id>-1)
			{
				point t=box[l[i]]-box[i];
				ans[box[i].id]=atan2(t.y,t.x);
				t=box[r[i]]-box[i];
				ans[box[i].id]-=atan2(t.y,t.x);
				ans[box[i].id]/=pi/180.0;
			}
		}
		printf("Case #%d:\n",cs);
		m-=n;
		for(int i=0;i<m;i++)
			printf("%.6f\n",ans[i]);
	}
}
时间: 2024-10-08 13:17:37

hdu5033Building的相关文章

HDU5033-Building(维护单调栈)

题目链接 题意:给出n座大楼的位置以及高度,再给出m个人的位置,查询给出的人的位置所能看到的最大的仰角是多少. 思路:维护每两座的楼之间的斜率,使之成为一个凸面,用栈来维护,听了GG小伙伴的思路,可以将人当作高度为0的大楼来带入计算. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using na