1. 程式人生 > >HDU5033 building 單調棧

HDU5033 building 單調棧

正解:單調棧

解題報告:

哇生氣遼QAQ本來打了半天feel good都快挑出來瞭然後說換題了QAQ

不過還是大爆手速打了一通拿到首殺了嘻嘻

美滋滋遼

然後放個傳送門先qwq

有一點點解題思想和oil是有點兒像的,就是先把詢問和修改放一個結構體裡排序,這樣當到達某個詢問的時候就可以直接解決不用進行其他修改了qwq

然後就是做兩次單調棧一次算出往左能看到的角度一次算出往右能看到的角度

然後就歐克遼?

ummm好像是沒什麼好說的了只要推出了角度計算然後維護一個斜率單調棧,然後就差不多了?

順便是不是可以總結下?就是這種計算幾何詢問+修改的經常會有放在一個數據結構裡然後排序的操作?這樣通常都會方便一些呢qwq

over?

程式碼放下我就做後面的題目辣qwq

 

#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; inline int read() { 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() { int T=read(); rp(j,1,T) { n=read();rp(i,1,n)bd[i].x=read(),bd[i].h=read(); q=read();rp(i,1,q)bd[i+n].x=read(),bd[i+n].h=-i; 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
這兒!是!程式碼!QwQ