BZOJ 2300 HAOI2011 防线修建 平衡树维护凸包
2014-11-02 15:56
405 查看
题目大意:给定初始三个点(0,0)(n,0)和(x,y),以及若干其它点,q次询问,每次删除一个点或求一次上凸包长度
平衡树维护凸包……和cash同样的思路为何我时隔2个月后的代码整整短了150行……
平衡树最好用set 链表的每个点存set的迭代器 直接erase很方便
这个题x值的下限和上限都是给定的 所以没有边界讨论 真赞~
一气呵成写出来 调了一小时 尼玛加点我居然加反了0.0
平衡树维护凸包……和cash同样的思路为何我时隔2个月后的代码整整短了150行……
平衡树最好用set 链表的每个点存set的迭代器 直接erase很方便
这个题x值的下限和上限都是给定的 所以没有边界讨论 真赞~
一气呵成写出来 调了一小时 尼玛加点我居然加反了0.0
#include<set> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define M 100100 #define INF 1e10 using namespace std; typedef pair<double,double> point; struct list; typedef set< pair<double,list*> >::iterator sit; struct list{ list *next,*last; point p; sit it; }head,tail; set< pair<double,list*> >s; int n,m,q; int queries[M<<1]; double stack[M];int top; point a[M]; bool v[M]; double len; double Distance(const point &p1,const point &p2) { return sqrt( (p1.first-p2.first)*(p1.first-p2.first) + (p1.second-p2.second)*(p1.second-p2.second) ); } double Get_Slope(const point &p1,const point &p2) { if(p1.first==p2.first) return p1.second<p2.second?INF:-INF; return (p1.second-p2.second)/(p1.first-p2.first); } void Insert(const point &p) { list *secc=s.lower_bound( make_pair(p.first,(list*)0x0) )->second; list *pred=secc->last; if( Get_Slope(pred->p,p)<Get_Slope(p,secc->p) ) return ; len-=Distance(pred->p,secc->p); while( pred!=&head && Get_Slope(pred->last->p,pred->p)<Get_Slope(pred->p,p) ) len-=Distance(pred->last->p,pred->p),s.erase(pred->it),pred=pred->last; while( secc!=&tail && Get_Slope(p,secc->p)<Get_Slope(secc->p,secc->next->p) ) len-=Distance(secc->p,secc->next->p),s.erase(secc->it),secc=secc->next; len+=Distance(pred->p,p); len+=Distance(p,secc->p); list *temp=pred->next=secc->last=new list; temp->last=pred; temp->next=secc; temp->p=p; temp->it=s.insert( make_pair(p.first,temp) ).first; } int main() { int i,x,y,p; cin>>m>>x>>y>>n; for(i=1;i<=n;i++) scanf("%lf%lf",&a[i].first,&a[i].second); cin>>q; for(i=1;i<=q;i++) { scanf("%d",&p); if(p==2) queries[i]=-1; else scanf("%d",&queries[i]),v[queries[i]]=1; } head.next=&tail; tail.last=&head; head.p=point(0,0); head.it=s.insert( make_pair(0,&head) ).first; tail.p=point(m,0); tail.it=s.insert( make_pair(m,&tail) ).first; len=m; Insert( point(x,y) ); for(i=1;i<=n;i++) if(!v[i]) Insert(a[i]); for(i=q;i;i--) { if(queries[i]==-1) stack[++top]=len; else Insert(a[queries[i]]); } while(top) printf("%.2lf\n",stack[top--]); }
相关文章推荐
- [BZOJ2300][HAOI2011]防线修建(平衡树动态维护凸包)
- 【BZOJ 2300】 [HAOI2011]防线修建 平衡树维护凸包
- [平衡树动态维护凸包] BZOJ 2300 [HAOI2011]防线修建
- bzoj 2300 [HAOI2011]防线修建 splay维护凸包
- [BZOJ]2300 [HAOI2011] 防线修建 动态维护凸包
- 【bzoj2300】[HAOI2011]防线修建 离线+STL-set维护凸包
- bzoj 2300: [HAOI2011]防线修建(splay动态维护凸包)
- 【BZOJ2300】[HAOI2011]防线修建 set维护凸包
- BZOJ 2300 HAOI 2011 防线修建 动态维护凸包
- bzoj 2300 [HAOI2011]防线修建 set动态维护凸包
- BZOJ 2300 [HAOI2011]防线修建 Splay维护动态凸包
- bzoj2300 [HAOI2011]防线修建 离线凸包
- [BZOJ2300][HAOI2011][动态凸包]防线修建
- bzoj 2300: [HAOI2011]防线修建 凸包
- 2300: [HAOI2011]防线修建 set维护凸包
- bzoj2300: [HAOI2011]防线修建【动态凸包】
- bzoj2300: [HAOI2011]防线修建 计算几何 凸包
- BZOJ 2300: [HAOI2011]防线修建|set维护凸壳
- BZOJ 2300: [HAOI2011]防线修建( 动态凸包 )
- bzoj 2300: [HAOI2011]防线修建