# 解题报告:

ummm好像是没什么好说的了只要推出了角度计算然后维护一个斜率单调栈,然后就差不多了?

over?

```#include <bits/stdc++.h>
using namespace std;
#define rp(i,x,y) for(register int i=x;i<=y;++i)

const double PI=acos(-1.0) ;
const int N=100000+100,inf=10000000;
struct node
{
int x,h;
bool operator<(const node &R)const{return x<R.x;}
}bd[N<<1],stk[N<<1];
double ans[N];
int n,q;

{
char ch=getchar();int x=0;bool y=1;
while(ch!=‘-‘ && (ch>‘9‘ || ch<‘0‘))ch=getchar();
if(ch==‘-‘)ch=getchar(),y=0;
while(ch>=‘0‘ && ch<=‘9‘)x=(x<<1)+(x<<3)+(ch^‘0‘),ch=getchar();
return y?x:-x;
}
inline bool judge(node a,node b,node c)
{
if(c.h<=0)c.h=0;
return (long long)(a.h-c.h)*(b.x-c.x)<=(long long)(b.h-c.h)*(a.x-c.x);
}
inline double xl(node a,node b){return atan(1.0*(b.x-a.x)/a.h);}
inline void solve()
{
int top=0;
rp(i,1,n+q)
{
if(bd[i].h<=0)
{
while(top>=2 && judge(stk[top-2],stk[top-1],bd[i]))--top;
ans[-bd[i].h]+=xl(stk[top-1],bd[i]);
continue;
}
while((top && stk[top-1].h<=bd[i].h) || (top>=2 && judge(stk[top-2],stk[top-1],bd[i])))--top;
stk[top++]=bd[i];
}
}

int main()
{
rp(j,1,T)
{
memset(ans,0,sizeof(ans));sort(bd+1,bd+n+q+1);solve();
reverse(bd+1,bd+n+q+1);rp(i,1,n+q)bd[i].x=inf-bd[i].x;solve() ;
printf("Case #%d:\n",j);rp(i,1,q)printf("%.10lf\n",(double)ans[i]*180/PI) ;
}
return 0;
}
//话说插入代码中编程语言c#和c++看起来有什么区别嘛qwq我有时候选c#有时候选c++感觉界面都一样鸭qwq```

HDU5033 building 单调栈

(0)
(0)

0条