hdu 5033 Building
2014-09-22 22:46
330 查看
//单调栈,和单调队列类似,求左边仰角时维护一个建筑高度呈凸型递减的栈,求右仰角维护高度呈凸型递增的栈
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<stack>
#define pi 3.1415926535898
using namespace std;
struct point
{
double x,h;int index;
}p[200010],sta[200010];
double ans[100010];
bool cmp(point a,point b)
{
return a.x<b.x;
}
int main()
{
int T;
scanf("%d",&T);
for(int cas=1;cas<=T;cas++)
{
int n;
memset(ans,0,sizeof(ans));
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].h);
p[i].index=0;
}
int Q;
scanf("%d",&Q);
for(int i=n;i<n+Q;i++)
{
scanf("%lf",&p[i].x);
p[i].h=0;
p[i].index=i-n+1;
}
sort(p,p+Q+n,cmp);
int top=0;
for(int i=0;i<n+Q;i++)
{
if(p[i].index>0)
{
while(top>1&&sta[top-1].h/(p[i].x-sta[top-1].x)<=(sta[top-2].h-sta[top-1].h)/(sta[top-1].x-sta[top-2].x))top--;
ans[p[i].index]+=atan(sta[top-1].h/(p[i].x-sta[top-1].x))/pi*180;
}
else
{
while(top>1&&(sta[top-1].h-p[i].h)/(p[i].x-sta[top-1].x)<=(sta[top-2].h-sta[top-1].h)/(sta[top-1].x-sta[top-2].x))top--;
sta[top++]=p[i];
}
}
top=0;
for(int i=n+Q-1;i>=0;i--)
{
if(p[i].index>0)
{
while(top>1&&sta[top-1].h/(sta[top-1].x-p[i].x)<=(sta[top-2].h-sta[top-1].h)/(sta[top-2].x-sta[top-1].x))top--;
ans[p[i].index]+=atan(sta[top-1].h/(sta[top-1].x-p[i].x))/pi*180;
}
else
{
while(top>1&&(sta[top-1].h-p[i].h)/(sta[top-1].x-p[i].x)<=(sta[top-2].h-sta[top-1].h)/(sta[top-2].x-sta[top-1].x))top--;
sta[top++]=p[i];
}
}
printf("Case #%d:\n",cas);
for(int i=1;i<=Q;i++)
{
printf("%.10lf\n",180.0-ans[i]);
}
}
return 0;
}
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<stack>
#define pi 3.1415926535898
using namespace std;
struct point
{
double x,h;int index;
}p[200010],sta[200010];
double ans[100010];
bool cmp(point a,point b)
{
return a.x<b.x;
}
int main()
{
int T;
scanf("%d",&T);
for(int cas=1;cas<=T;cas++)
{
int n;
memset(ans,0,sizeof(ans));
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].h);
p[i].index=0;
}
int Q;
scanf("%d",&Q);
for(int i=n;i<n+Q;i++)
{
scanf("%lf",&p[i].x);
p[i].h=0;
p[i].index=i-n+1;
}
sort(p,p+Q+n,cmp);
int top=0;
for(int i=0;i<n+Q;i++)
{
if(p[i].index>0)
{
while(top>1&&sta[top-1].h/(p[i].x-sta[top-1].x)<=(sta[top-2].h-sta[top-1].h)/(sta[top-1].x-sta[top-2].x))top--;
ans[p[i].index]+=atan(sta[top-1].h/(p[i].x-sta[top-1].x))/pi*180;
}
else
{
while(top>1&&(sta[top-1].h-p[i].h)/(p[i].x-sta[top-1].x)<=(sta[top-2].h-sta[top-1].h)/(sta[top-1].x-sta[top-2].x))top--;
sta[top++]=p[i];
}
}
top=0;
for(int i=n+Q-1;i>=0;i--)
{
if(p[i].index>0)
{
while(top>1&&sta[top-1].h/(sta[top-1].x-p[i].x)<=(sta[top-2].h-sta[top-1].h)/(sta[top-2].x-sta[top-1].x))top--;
ans[p[i].index]+=atan(sta[top-1].h/(sta[top-1].x-p[i].x))/pi*180;
}
else
{
while(top>1&&(sta[top-1].h-p[i].h)/(sta[top-1].x-p[i].x)<=(sta[top-2].h-sta[top-1].h)/(sta[top-2].x-sta[top-1].x))top--;
sta[top++]=p[i];
}
}
printf("Case #%d:\n",cas);
for(int i=1;i<=Q;i++)
{
printf("%.10lf\n",180.0-ans[i]);
}
}
return 0;
}
相关文章推荐
- hdu 5033 ( Building ) 单调栈
- HDU 5033 Building
- HDU 5033 Building --离线+单调栈
- HDU 5033 Building(类凸包+向量叉积的应用)
- hdu 5033 Building 几何+单调栈
- hdu-5033-Building
- HDU 5033 Building(DP,2014北京网络赛1002)
- hdu 5033 Building(北京网络赛)
- HDU 5033 Building
- Hdu 5033 Building(2014 ACM/ICPC Asia Regional Beijing Online1002) [几何]
- hdu 5033——Building
- HDU 5033---Building(单调栈)
- HDU 5033-B - Building-维护凸包-单调栈
- HDU 5033 Building 单调队列
- HDU 5033 Building(2014北京网络赛 单调栈+几何)
- hdu 5033 Building 2014 ACM/ICPC Asia Regional Beijing Online
- HDU 5033 Building (单调栈维护凸包)
- HDU 5033 Building(单调栈, 类凸包)
- HDU 5033 Building 解题报告(维护凸包)
- hdu 5033 Building(单调性+二分)