题目链接: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. NHibernate学习笔记

    原文详见http://www.cnblogs.com/GoodHelper/archive/2011/02/16/nhibernate_03.html   NHibernate_Demo程序框架: D ...

  2. Bootstrap 模态框插件

    一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素,分别为 modal(模态声明层). dialog(窗口声明层).content(内容层).在内容层里面,还有三层,分别为 header(头 ...

  3. BLE-NRF51822教程17-DFU使用手机升级

    演示的工程是 [application]    nRF51_SDK_10.0.0_dc26b5e\examples\ble_peripheral\ble_app_hrs\pca10028\s110_w ...

  4. linqPad帮助你快速学习LINQ

    linqPad http://www.cnblogs.com/li-peng/p/3441729.html http://www.linqpad.net/ Linqer http://www.sqlt ...

  5. android jdbc 远程数据库

    http://blog.csdn.net/conowen/article/details/7435231/

  6. 自己diy一个jquery分页插件

    js基础学习过程中,期间经历换工作的各种面试,很多面试官问过:有没有写过jquery插件?等类似问题. 就个人而言,关于jquery插件的文章确实看过不少,但是一直没有动手写一个,一是不想在目前学习j ...

  7. 消息队列系列(一):.Net平台下的消息队列介绍

    本系列主要记录最近学习消息队列的一些心得体会,打算形成一个系列文档.开篇主要介绍一下.Net平台下一些主流的消息队列框架.       RabbitMQ:http://www.rabbitmq.com ...

  8. NDK编译FreeImage

    参考了 以下2篇文章 并作了一小点修改 http://recursify.com/blog/2013/05/25/building-freeimage-for-android http://blog. ...

  9. [LeetCode]题解(python):047-Permutations II

    题目来源 https://leetcode.com/problems/permutations-ii/ Given a collection of numbers that might contain ...

  10. appium testcase1(Java)

    官网源码地址 https://github.com/appium/sample-code/blob/47fc0305396b8322b727820ca55a07607395040c/sample-co ...