传送门

题意:动态插入点,维护凸包面积。


思路:用setsetset维护极角序来支持面积查询即可。

然后注意选原点的时候要从初始三个点随机平均系数来避免精度误差。

代码:

#include<bits/stdc++.h>
#define ri register ll
using namespace std;
typedef long long ll;
inline ll read(){
    ll ans=0;
    bool f=1;
    char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f^=1;ch=getchar();}
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return f?ans:-ans;
}
struct pot{
    ll x,y;
    double ang;
    pot(ll _x=0,ll _y=0):x(_x),y(_y){}
    pot(ll _x,ll _y,double _ang):x(_x),y(_y),ang(_ang){}
    friend inline pot operator+(const pot&a,const pot&b){return pot(a.x+b.x,a.y+b.y);}
    friend inline pot operator-(const pot&a,const pot&b){return pot(a.x-b.x,a.y-b.y);}
    friend inline ll operator^(const pot&a,const pot&b){return (ll)a.x*b.y-(ll)a.y*b.x;}
    friend inline bool operator<(const pot&a,const pot&b){return a.ang<b.ang;}
}a[5];
set<pot>S;
typedef set<pot>::iterator It;
ll n;
ll ans=0;
inline ll Area(const pot&a,const pot&b,const pot&c){return (a-c)^(b-c);}
inline ll labs(const ll&x){return x>0?x:-x;}
inline pot Pre(const pot&now){
    if(S.count(now)>0)return now;
    It it=S.lower_bound(now);
    if(it==S.begin())it=S.end();
    return *(--it);
}
inline pot Suf(const pot&now){
    It it=S.upper_bound(now);
    if(it==S.end())it=S.begin();
    return *it;
}
inline bool check(const pot&x){return Area(x,Suf(x),Pre(x))<=0;}
inline void insert(const pot&x){
    if(check(x))return;
    ans+=labs(Area(x,Suf(x),Pre(x)));
    while(1){
        pot p1=Pre(x),p2;
        S.erase(p1);
        p2=Pre(x);
        if(Area(x,p2,p1)>=0){S.insert(p1);break;}
        ans+=labs(Area(x,p2,p1));
    }
    while(1){
        pot p1=Suf(x),p2;
        S.erase(p1);
        p2=Suf(x);
        if(Area(x,p2,p1)<=0){S.insert(p1);break;}
        ans+=labs(Area(p1,p2,x));
    }
    S.insert(x);
}
signed main(){
    srand(time(NULL));
    ll xxx=rand(),yyy=rand(),zzz=rand(),ttt=xxx+yyy+zzz;
    double X,Y;
    a[1].x=read(),a[1].y=read();
    a[2].x=read(),a[2].y=read();
    a[3].x=read(),a[3].y=read();
    X=(double)((ll)a[1].x*xxx+(ll)a[2].x*yyy+(ll)a[3].x*zzz)/ttt;
    Y=(double)((ll)a[1].y*xxx+(ll)a[2].y*yyy+(ll)a[3].y*zzz)/ttt;
    for(ri i=1;i<=3;++i)S.insert(pot(a[i].x,a[i].y,atan2(a[i].y-Y,a[i].x-X)));
    ans=labs(Area(a[1],a[2],a[3]));
    for(ri x,y,tt=read();tt;--tt){
        x=read(),y=read();
        insert(pot(x,y,atan2(y-Y,x-X)));
        cout<<ans<<'\n';
    }
    return 0;
}

2019.02.21 bzoj1249: SGU277 HERO 动态凸包(set+凸包)的更多相关文章

  1. bzoj1249: SGU277 HERO 动态凸包

    动态维护凸包面积. //Achen #include<bits/stdc++.h> #define For(i,a,b) for(int i=(a);i<=(b);i++) #def ...

  2. 2019.02.21 bzoj2300: [HAOI2011]防线修建(set+凸包)

    传送门 题意:动态维护凸包周长. 思路: 见这篇求面积的吧反正都是一个套路. 代码: #include<bits/stdc++.h> #define int long long #defi ...

  3. 2019.02.21 bzoj5317: [Jsoi2018]部落战争(凸包+Minkowski和)

    传送门 题意:qqq次询问把一个凸包整体加一个向量(x,y)(x,y)(x,y)之后是否与另外一个凸包相交. 思路:转化一下发现只要会求A+B={v⃗=a⃗+b⃗∣a⃗∈A,b⃗∈B}A+B=\{\v ...

  4. 2019.02.21 bzoj2829: 信用卡凸包(凸包)

    传送门 题意:给nnn个A∗BA*BA∗B的矩形,其中每个矩形的四个角被改造成了半径为rrr的四分之一 圆,问这些矩形的凸包周长. 思路:考虑求出圆心的凸包周长然后加上一个整圆的周长,证明很简单,略掉 ...

  5. 2019.02.26 bzoj4311: 向量(线段树分治+凸包)

    传送门 题意: 支持插入一个向量,删去某一个现有的向量,查询现有的所有向量与给出的一个向量的点积的最大值. 思路: 考虑线段树分治. 先对于每个向量处理出其有效时间放到线段树上面,然后考虑查询:对于两 ...

  6. 2019.02.21 bzo1038: [ZJOI2008]瞭望塔(半平面交)

    传送门 题意:给出一个nnn个点的轮廓,要求找一个高度最小的点使得它能够看见所有拐点. 思路:之间建半平面交然后取半平面交上的每个交点和每个轮廓更新答案即可. 代码: #include<bits ...

  7. 2019.02.21 bzoj2739: 最远点(决策单调性+分治)

    传送门 题意简述:给一个N个点的凸多边形,求离每一个点最远的点. 思路:先根据初中数学知识证明决策是满足单调性的,然后上分治优化即可. 才不是因为博主懒得写二分+栈优化呢 代码: #include&l ...

  8. FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM

    FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM T.. = Timeline support 支持时间轴 .S. = Slice t ...

  9. http://www.cnblogs.com/xwdreamer/archive/2012/02/21/2360818.html

    http://www.cnblogs.com/xwdreamer/archive/2012/02/21/2360818.html

随机推荐

  1. 当一个HTML元素需要添加mouseon、mouseout与click事件,或者mouserenter、mouseleave和click事件时,click事件无法触发

    当一个HTML元素需要添加mouseon.mouseout与click事件,或者mouserenter.mouseleave和click事件时,click事件无法触发 针对上述问题,我遇到的有两种情况 ...

  2. 剑指offer题目解答合集(C++版)

    数组中重复的数字 二维数组中查找 字符串 替换空格 二叉树的编码和解码 从尾到头打印链表 重建二叉树 二叉树的下一个节点 2个栈实现队列 斐波那契数列 旋转数字 矩阵中的路径 机器人的运动范围 剪绳子 ...

  3. web socket client

    <!DOCTYPE HTML> <html> <head> <title>My WebSocket</title> </head> ...

  4. git 第一次提交代码

    git init git add README.md git commit -m "first commit" git remote add origin https://git. ...

  5. 注解_Annotation

    ---恢复内容开始--- 一.什么是注解 注解,英文Annotation,它不是程序本身,是对程序的解释,在这里我会想到为什么不能使用注释呢,因为注解是关于程序对信息的处理的流程的一些说明,而且格式也 ...

  6. php中使用com组件出现"拒绝访问"的处理

    php中使用com组件出现"拒绝访问"的处理 2010年05月14日 12:28:00 阅读数:1529 代码如下, // 建立一个指向新COM组件的索引 $word = new ...

  7. web设计工具

    1.工具    WYSIWYG_Web_Builder_12 2.网页    https://bootstrapstudio.io/#purchase

  8. C# dns.gethostentry()获取失败,提示不存在主机

    传入参数domain有误. 如果是域名,可以解析.如果是局域ip可以解析. 如果是外网,解析不成功. 解决方法: 判断传入参数是域名还是ip,如果是域名,则使用dns.gethostentry(dom ...

  9. 使用Pyquery+selenium抓取淘宝商品信息

    配置文件,配置好数据库名称,表名称,要搜索的产品类目,要爬取的页数 MONGO_URL = 'localhost' MONGO_DB = 'taobao' MONGO_TABLE = 'phone' ...

  10. GCD - Extreme (II) (欧拉函数妙用)

    https://cn.vjudge.net/problem/UVA-11426 题意:求 解题思路:我们可以定义一个变量dis[n],dis[n]意为1~(n-1)与n的gcd(最大公约数)的总和,那 ...