题目链接:http://codeforces.com/problemset/problem/70/D

本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包

判断:平衡树log(n)内选出点所属于的区域

插入:平衡树log(n)内选出点所属于的区域, 与做一般凸包的时候类似,分别以该点向左右两边进行维护,

一直删除不满足凸包的点,直到所有点满足凸包为止。

水平序:

可以用2个平衡树分别维护上下2个半凸包,具体实现时可以把其中一个半凸包按y轴对称以后,那么2个半凸包的维护就是同一种方法,写2个函数就ok了。

具体平衡树可以用set或map,用STL以后边界处理有点烦,需要注意。

水平序的凸包有一个特点(如按x排序):对于上下凸包(分开来看),x相同的点只有一个。所以用set维护比较麻烦,用map维护相对容易一点。

极角序:

之前给你的3个点一定是插入的,可以选它们的中心点o作为之后的凸包中心,按o进行极角排序。

之后的做法就跟 “本题关键” 的做法一致。

以下给出3份不同的代码:

set代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef set <pii > ::iterator iter;
#define mp make_pair
#define X first
#define Y second
int q, op, x, y;
set <pii > up, down;
const int inf = 1e9;
ll cross(pii o, pii a, pii b) {return (ll)(a.X-o.X)*(b.Y-o.Y) - (ll)(a.Y-o.Y)*(b.X-o.X);
}
bool inside(set<pii > &st, int x, int y) {if(!st.size()) return 0;if(x < st.begin()->X || x > st.rbegin()->X) return 0;iter c = st.lower_bound(mp(x, -inf));//如果有相同x的点,比较y值即可if(c != st.end() && c->X == x)return y >= c->Y;iter r = st.lower_bound(mp(x, y));iter l = r; l--;return  cross(*l, mp(x, y), *r) <= 0;
}
void add(set<pii > &st, int x, int y)
{if(inside(st, x, y)) return;iter c = st.lower_bound(mp(x, -inf));if(c != st.end() && c->X == x)   //如果有相同x的点必须删除st.erase(c);st.insert(mp(x, y));iter cur = st.lower_bound(mp(x, y)), i, j;for(i = cur, i--, j = i, j--; i != st.begin() && cur != st.begin(); i = j, j--)if(cross(*cur, *i,*j) >= 0) st.erase(i);else break;for(i = cur, i++, j = i, j++; i != st.end() && j != st.end(); i = j, j++)if(cross(*cur, *i, *j) <= 0) st.erase(i);else break;
}int main() {scanf("%d", &q);while(q--) {scanf("%d%d%d", &op, &x, &y);if(op == 1) {add(up, x, -y);add(down, x, y);}else if(inside(up, x, -y) && inside(down, x, y))puts("YES");else puts("NO");}return 0;
}

map代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
#define X first
#define Y second
typedef map<int, int> mii;
typedef map<int, int>::iterator iter;
typedef long long ll;
ll cross(iter o, iter a, iter b) {return  (ll)(a->X-o->X)*(b->Y-o->Y)-(ll)(a->Y-o->Y)*(b->X-o->X);
}
mii up, down;
bool inside(mii &p, int x, int y) {if(!p.size()) return 0;if(x < p.begin()->X || x > p.rbegin()->X) return 0;if(p.count(x)) return y >= p[x];p[x] = y;iter cur = p.lower_bound(x), i, j;i = cur; j = cur; j++; i--;bool ret = cross(i, cur, j) <= 0;p.erase(x);return ret;
}
void add(mii &p, int x, int y) {if (inside(p, x, y))return;p[x] = y;iter cur = p.lower_bound(x), i, j;for (i = cur, i--, j = i, j--; i != p.begin() && cur != p.begin();i = j--)if (cross(cur, i, j) >= 0) p.erase(i);else break;for (i = cur, i++, j = i, j++; i != p.end() && j != p.end();i = j++)if (cross(cur, i, j) <= 0) p.erase(i);else break;
}
int main() {int i, j, Q, x, y, op;scanf("%d", &Q);while (Q--) {scanf("%d%d%d", &op, &x, &y);if (op == 1) {add(up, x, -y);add(down, x, y);} else if (inside(up, x, -y) && inside(down, x, y))printf("YES\n");elseprintf("NO\n");}return 0;
}

极角序代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
struct point {int x, y;ll d;double z;
}o, a[5], p;
typedef set <point>:: iterator iter;
bool operator <(const point &a, const point &b) {return a.z < b.z || (a.z == b.z && a.d < b.d);
}ll cross(point o, point a, point b) {return (ll)(a.x-o.x)*(b.y-o.y)-(ll)(a.y-o.y)*(b.x-o.x);
}
set <point> st;
iter L(iter x) {if(x == st.begin()) x = st.end();x--;return x;
}
iter R(iter x) {x++;if(x == st.end()) x = st.begin();return x;
}int q, op;
int main() {scanf("%d", &q);for(int i = 0; i < 3; i++) {scanf("%d%d%d", &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(int i = 0; i < 3; i++) {a[i].d = (ll)(a[i].x-o.x)*(a[i].x-o.x)+(ll)(a[i].y-o.y)*(a[i].y-o.y);a[i].z = atan2(a[i].y-o.y, a[i].x-o.x);st.insert(a[i]);}q -= 3;while(q--) {scanf("%d%d%d", &op, &p.x, &p.y);p.x *= 3; p.y *= 3;p.z = atan2(p.y-o.y, p.x-o.x);p.d = (ll)(p.x-o.x)*(p.x-o.x)+(ll)(p.y-o.y)*(p.y-o.y);iter i = st.lower_bound(p), j;if(i == st.end()) i = st.begin();j = L(i);if(op == 2) {if(cross(*j,p,*i)<=0) puts("YES");else puts("NO");continue;}if(cross(*j,p,*i)<=0) continue;st.insert(p);iter cur = st.find(p);i = L(cur); j = L(i);while(cross(*j, *i, *cur) <= 0) {st.erase(i);i = j;  j = L(j);}i = R(cur); j = R(i);while(cross(*j, *i, *cur) >= 0) {st.erase(i);i = j; j = R(j);}}return 0;
}

Codeforces 70D 动态凸包 (极角排序 or 水平序)相关推荐

  1. Grandpa's Estate POJ - 1228(凸包极角序改写)

    看了题目意思之后感觉哇,简单的 一批不就是判断线段之间有没有至少一个点嘛,,,,,结果wa到自闭,, 这个题的点有首先要根据点构造凸包,因为题目给的数据不一定是一个凸包,其次,我们在构造凸包极角排序的 ...

  2. 【CCCC】L3-009 长城 (30分),计算几何+凸包,极角排序

    problem L3-009 长城 (30分) 正如我们所知,中国古代长城的建造是为了抵御外敌入侵.在长城上,建造了许多烽火台.每个烽火台都监视着一个特定的地区范围.一旦某个地区有外敌入侵,值守在对应 ...

  3. codeforces 598C C. Nearest vectors(极角排序)

    题目链接: C. Nearest vectors time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  4. 凸包问题--动态凸包(平衡树维护)

    前景提要: 继承上一张学习的凸包问题,下面我么来总结一下动态凸包的维护问题. 一些点已经构成了一个凸包之后,新加入||删除一些新的点的时候,会对原有的凸包产生一些影响,如果每次都重新把所有点都重新计算 ...

  5. 简单几何(极角排序) POJ 2007 Scrambled Polygon

    题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...

  6. Flutter ListView (动态)列表组件、水平列表组件、图标组件详解

    Flutter ListView (动态)列表组件.水平列表组件.图标组件 Flutter ListView 基础列表组件.水平列表组件.图标组件 列表常见的几种情况: 垂直列表 垂直图文列表 横向列 ...

  7. hdu 5107 线段树+离散化+归并排序+极角排序

    首先这道题的数据范围极大,那么一定是要离散化的,离散化就是读入之后,记录id,分别按照x和y排序,排序之后重新记录成连续的坐标 然后数据量也挺大,而且没有重点,所以直接极角排序,然后将横坐标映射到一棵 ...

  8. R语言ggplot2可视化整体排序的水平堆叠条形图(Ordered Stacked Horizontal Barplot)

    R语言ggplot2可视化整体排序的水平堆叠条形图(Ordered Stacked Horizontal Barplot) 目录 R语言ggplot2可视化整体排序的水平堆叠条形图(Ordered S ...

  9. CF70D Professor's task(动态凸包)

    题面 两种操作: 1 往点集S中添加一个点(x,y); 2 询问(x,y)是否在点集S的凸包中. 数据保证至少有一个2操作, 保证刚开始会给出三个1操作, 且这三个操作中的点不共线. 题解 动态凸包板 ...

最新文章

  1. 【鸿蒙 HarmonyOS】UI 组件 ( Text 组件 )
  2. python代码编写规范有哪些_Python代码编写规范(适合于小团体,低强度)
  3. 蓝桥杯 试题 基础练习 龟龟龟龟龟兔赛跑预测——18行代码AC
  4. 使用Nginx搭建图片服务器(windows7)
  5. 《方舟生存进化》单机存档损坏解决方法
  6. UVA11039 Building designing【排序】
  7. Inondb中的checkpoint
  8. js数组(列表)的基本操作
  9. 走迷宫(三):在XX限制条件下,是否走得出。
  10. 数组对象转json格式
  11. 测试用例设计设计方法——正交实验法
  12. 如何无损把mp4视频格式转换成mp3音频格式
  13. java 计算天数差_java中计算两个日期之间差的天数
  14. 8box播放器的引用
  15. numpy操作技巧二三事
  16. 京东产品上架如何批量上传商品素材?
  17. reset.css(常用项目代码初始化)
  18. ArcGIS Engine 10.5下构建Java程序—轻松入门
  19. mysql表关联查询都有什么方式_所有关联表查询方式
  20. 科技+卫生=智慧公厕,城市焕然一新!

热门文章

  1. 苹果手机数据转移到新手机_手机通讯录怎么转移到新手机?找对方法就可以了...
  2. Openstack中用秘钥对(keypair)生成和访问虚机的方法
  3. MATLAB中语音加噪,语音信号加噪和降噪处理
  4. batch size的作用
  5. 10 判断素数 (10分)
  6. 安全基础知识--面试
  7. 计算机产业scp分析,SCP框架下的网络杂志产业分析
  8. 使用mars3d的几种方式
  9. Android中的Serializable和Parcelable序列化
  10. 21篇python基础教程