Codeforces 70D Professor's task [动态凸包]
2017-07-31 13:39
316 查看
题意:初始给你三个点,之后有若干操作
①加入一个点,使点集成为一个新的凸包
②判断一个点是否在凸包中
题解:对点进行极角排序(用set维护),判断点是否在凸包内时,查找该点的前驱和后继,判断叉积即可。对于加入的点的操作,我们需要将点插入set用判断凸包的方法,从该点出发,对其左右进行判断。
AC代码:
4000
①加入一个点,使点集成为一个新的凸包
②判断一个点是否在凸包中
题解:对点进行极角排序(用set维护),判断点是否在凸包内时,查找该点的前驱和后继,判断叉积即可。对于加入的点的操作,我们需要将点插入set用判断凸包的方法,从该点出发,对其左右进行判断。
AC代码:
#include<stdio.h> #include<set> #include<math.h> using namespace std; typedef long long ll; struct point { ll x,y; ll len; double ang; point(){} point(ll x,ll y) { this->x=x; this->y=y; } }o,a[5]; ll q; set<point>st; set<point>::iterator qian,hou,it; bool operator<(point a,point b) { if(a.ang==b.ang)return a.len<b.len; return a.ang<b.ang; } point operator-(point A,point B) //点-点=向量 { return point(A.x-B.x,A.y-B.y); } ll Cross(point A,point B) //叉积 { return A.x*B.y-A.y*B.x; } set<point>::iterator L(set<point>::iterator x) { if(x == st.begin()) x = st.end(); x--; return x; } set<point>::iterator R(set<point>::iterator x) { x++; if(x == st.end()) x = st.begin(); return x; } int main() { scanf("%lld",&q); ll op; for(ll i=0;i<3;i++) { scanf("%lld%lld%lld",&op,&a[i].x,&a[i].y); o.x+=a[i].x; o.y+=a[i].y; a[i].x*=3; a[i].y*=3; } for(ll i=0;i<3;i++) { a[i].len=(ll)(a[i].y-o.y)*(a[i].y-o.y)+(ll)(a[i].x-o.x)*(a[i].x-o.x); a[i].ang=atan2(a[i].y-o.y,a[i].x-o.x); st.insert(a[i]); } q-=3; while(q--) { ll x,y; scanf("%lld%lld%lld",&op,&x,&y); x*=3,y*=3; point p=point(x,y); p.len=(ll)(y-o.y)*(y-o.y)+(ll)(x-o.x)*(x-o.x); p.ang=atan2(y-o.y,x-o.x); hou=st.lower_bound(p); if(hou==st.end())hou=st.begin(); qian=L(hou); if(op==1) { if(Cross(p-*qian,*hou-p)<=0)continue; st.insert(p); set<point>::iterator cur,i,j; cur=st.find(p); i=L(cur);j=L(i); while(Cross(*j-*cur,*i-*j) <= 0) { st.erase(i); i=j;j=L(j); } i=R(cur);j=R(i); while(Cross(*j-*cur,*i-*j) >= 0) { st.erase(i); i=j;j=R(i); } } else { if(Cross(p-*qian,*hou-p)<=0)printf("YES\n"); else printf("NO\n"); } } }
4000
相关文章推荐
- codeforces 70D Professor's task(动态二维凸包)
- Codeforces 70D 动态凸包 (极角排序 or 水平序)
- Codeforces 70D 动态凸包(极角排序)
- [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)
- codeforces 70 D. Professor's task 动态凸包
- BZOJ 2300 HAOI 2011 防线修建 动态维护凸包
- Codeforces 915E 线段树动态开点
- bzoj3963 [WF2011]MachineWorks(斜率优化 & splay维护动态凸包)
- BZOJ1492:[NOI2007]货币兑换 (CDQ分治+斜率优化DP | splay动态维护凸包)
- hdu4573 Throw the Stones(动态三维凸包)
- [BZOJ2300][HAOI2011]防线修建(平衡树动态维护凸包)
- codeforces 620D D. Professor GukiZ and Two Arrays
- 平衡树维护动态凸包
- 动态凸包问题
- [DP 斜率优化 CDQ分治||动态维护凸包] BZOJ 1492 [NOI2007]货币兑换Cash
- 动态凸包 学习总结
- CodeForces 11D(动态规划-状压dp)
- Codeforces-785E-Anton and Permutation(分块区间查询,动态查询[l,r]内小于某个值的元素个数)
- CodeForces - 1017E :The Supersonic Rocket (几何+KMP,判定凸包是否同构)
- 70D - Professor's task