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

Once a walrus professor Plato asked his programming students to perform the following practical task.

The students had to implement such a data structure that would support a convex hull on some set of points S. The input to the program had q queries of two types:

1. Add a point with coordinates (x, y) into the set S. Note that in this case the convex hull of S could have changed, and could have remained the same.

2. Say whether a point with coordinates (x, y) belongs to an area limited by the convex hull, including the border.

All the students coped with the task. What about you?

Input

The first line contains an integer q (4 ≤ q ≤ 105).

Then follow q lines in the following way: "t x y", where t is the query type (1 or 2), and (x, y) are the coordinates of the point ( - 106 ≤ x, y ≤ 106, x and y are integers).

There is at least one query of type 2.

It is guaranteed that the three queries of the first type follow first and the points given in the queries form a non-degenerative triangle. Also all the points added in S are distinct.

Output

For each query of the second type print one string containing "YES", if the point lies inside the convex hull or on its border. Otherwise, print "NO".

题目大意:q个操作。操作1:往点集中添加一个点。操作2:给一个点,问这个点是否在点集所构成的凸包内部(包括边缘)。

思路:增量法求动态凸包。可以看:http://blog.csdn.net/crazy_ac/article/details/8499443

PS:原来map的迭代器是首尾相连的……

代码(156MS):

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
typedef map<int, int> MPII; struct Point {
int x, y;
Point() {}
Point(int x, int y): x(x), y(y) {}
Point(MPII::iterator it): x(it->first), y(it->second) {}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
}; LL cross(const Point &a, const Point &b) {
return (LL)a.x * b.y - (LL)a.y * b.x;
} LL cross(const Point &o, const Point &a, const Point &b) {
return cross(a - o, b - o);
} bool below(MPII &mp, Point p) {
if(mp.empty()) return false;
if(p.x < mp.begin()->first || mp.rbegin()->first < p.x) return false;
MPII::iterator a = mp.lower_bound(p.x), b = a--;
if(b->first == p.x) return b->second >= p.y;
return cross(a, b, p) <= ;
} void insert(MPII &mp, Point p) {
if(below(mp, p)) return ;
MPII::iterator a, b, it;
mp[p.x] = p.y;
it = mp.lower_bound(p.x); b = it; ++b;
if(b != mp.end()) {
a = b++;
while(b != mp.end() && cross(p, a, b) >= )
mp.erase(a), a = b++;
} a = it; --a;
if(it != mp.begin() && a != mp.begin()) {
b = a--;
while(b != mp.begin() && cross(p, b, a) <= )
mp.erase(b), b = a--;
}
} MPII up, down;
int q, op, x, y; int main() {
scanf("%d", &q);
while(q--) {
scanf("%d%d%d", &op, &x, &y);
if(op == ) {
insert(up, Point(x, y));
insert(down, Point(x, -y));
} else {
puts((below(up, Point(x, y)) && below(down, Point(x, -y))) ? "YES" : "NO");
}
}
}

codeforces 70D Professor's task(动态二维凸包)的更多相关文章

  1. Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积

    Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...

  2. C++ 里 构建动态二维数组

    //****动态二维数组 /* int m=3; int **data; int n=2; data=new int*[m]; for(int j=0;j<m;j++) { data[j]=ne ...

  3. C++动态二维数组的创建

    两种方式. 一,二级指针,创建2行3列的动态二维数组. 这里,p指向的是2个地址,这两个地址各指向长度为3的一维整型数组. 在内存中,每行元素内部顺序排列.两行元素的首地址不同,p[1]与p[2]存放 ...

  4. C++建立动态二维数组

    C++建立动态二维数组主要有两种方法: 1.使用数组指针,分配一个指针数组,将其首地址保存在b中,然后再为指针数组的每个元素分配一个数组                           int * ...

  5. php 合并图片 (将活动背景图片和动态二维码图片合成一张图片)

    <?php //案例一:将活动背景图片和动态二维码图片合成一张图片 //图片一 $path_1 = './background.png'; //图片二 $path_2 = './FU0851_2 ...

  6. 动态二维数组赋值及for循环遍历和toString遍历

    package com.Summer_0421.cn; import java.util.Arrays; /** * @author Summer * 动态二维数组赋值及for循环遍历和toStrin ...

  7. 以杨辉三角为例,从内存角度简单分析C语言中的动态二维数组

    学C语言,一定绕不过指针这一大难关,而指针最让人头疼的就是各种指向关系,一阶的指针还比较容易掌握,但一旦阶数一高,就很容易理不清楚其中的指向关系,现在我将通过杨辉三角为例,我会用四种方法从内存的角度简 ...

  8. python小工具myqr生成动态二维码

    python小工具myqr生成动态二维码 (一)安装 (二)使用 (一)安装 命令: pip install myqr 安装完成后,就可以在命令行中输入 myqr 查看下使用帮助: myqr --he ...

  9. Python | 一行命令生成动态二维码

    当我看到别人的二维码都做的这么炫酷的时候,我心动了! 我也想要一个能够吸引眼球的二维码,今天就带大家一起用 Python 来做一个炫酷的二维码! 首先要安装工具 myqr: pip install m ...

随机推荐

  1. pro7

    1.本次课学习到的知识点: 函数的作用 确定函数的功能 定义函数 调用函数 2.实验过程中遇到的问题及解决方法: 定义函数时 变量的定义会出现混乱 通过看例题 多练习 逐渐熟悉 需从数学角度解决问题时 ...

  2. 安装SQL Server出现在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke的错误解决办法

    以下是错误报告:   标题: SQL Server 安装程序失败. ------------------------------   SQL Server 安装程序遇到以下错误:   在创建窗口句柄之 ...

  3. 【C51】单片机芯片之——图解74HC595

    第一部部分用于快速查阅使用,详细的使用见文章第二部分 引脚图

  4. CentOS 7.0下面安装并配置Spark

    安装环境: 虚拟机:VMware® Workstation 8.0.1(网络桥接) OS:CentOS 7 JDK版本:jdk-7u79-linux-x64.tar Scala版本:scala-2.1 ...

  5. 单个未知大小图片在div里面垂直居中的方法。。。添加辅助元素挤一下位置达到居中

    单个未知大小图片在div里面垂直居中的方法...添加辅助元素挤一下位置达到居中   <div class="ServicesLiTopPic"> <i>&l ...

  6. 安装MVC3后没有dbcontext生成器的解决方案

    安装MVC3后,采用DBFIRS的方式,从数据库生成模型,这样生成的类是基于ObjectContext的,无法使用DbContext的一些方法,比如Set.Find.Entry等.需要用ADO.NET ...

  7. 关于带透明度的灰度层的show、hide

    原理图如下:[需要注意的是,灰度View与中间的小View是并列的关系,否则,带透明度的灰度图就会影响小View的透明度] - (void)show{ UIWindow *win = [[UIAppl ...

  8. Introduction to Project Management(I)

    Project management in the modern sense began in the early 1950s, although it has its roots further b ...

  9. C++经典编程题#3:数字求和

    总时间限制:  1000ms 内存限制:  65536kB 描述 给定一个正整数a,以及另外的5个正整数,问题是:这5个整数中,小于a的整数的和是多少? 输入 输入一行,只包括6个小于100的正整数, ...

  10. imx6 lvds 代码分析

    查看imx6 kernel中lvds设备和驱动的初始化过程. 相关文档: arm/arm/mach-mx6/board-mx6q_sabresd.c kernel/drivers/video/mxc/ ...