zoukankan      html  css  js  c++  java
  • CF1142C U2(计算几何,凸包)

    题目大意:平面上有 $n$ 个点,第 $i$ 个点是 $(x_i,y_i)$。问有多少条抛物线(二次项系数为 $1$),经过这些点中不同的两个点,并且内部(不含边界)没有任何这些点。重合的抛物线只算一次。

    $1le nle 10^5,|x_i|,|y_i|le 10^6$。


    这题特别有趣。

    考虑把抛物线方程重写:$y-x^2=bx+c$。

    那么如果把每个点变成 $(x_i,y_i-x_i^2)$,那么原来 $i,j$ 两点的抛物线就变成了现在 $i,j$ 两点的直线。

    那么答案就是上凸包的边数。

    时间复杂度 $O(nlog n)$。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=100010;
    #define FOR(i,a,b) for(int i=(a);i<=(b);i++)
    #define ROF(i,a,b) for(int i=(a);i>=(b);i--)
    #define MEM(x,v) memset(x,v,sizeof(x))
    inline int read(){
        char ch=getchar();int x=0,f=0;
        while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
        while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
        return f?-x:x;
    }
    struct point{
        ll x,y;
        bool operator<(const point &p)const{
            if(x!=p.x) return x>p.x;
            return y>p.y;
        }
        point operator-(const point &p)const{
            return (point){x-p.x,y-p.y};
        }
    }p[maxn],pp[maxn],stk[maxn];
    int n,m,tp;
    ll cross(point p1,point p2){
        return p1.x*p2.y-p2.x*p1.y;
    }
    int main(){
        n=read();
        FOR(i,1,n) p[i].x=read(),p[i].y=read()-p[i].x*p[i].x;
        sort(p+1,p+n+1);
        pp[m=1]=p[1];
        FOR(i,2,n) if(p[i].x!=p[i-1].x) pp[++m]=p[i];
        FOR(i,1,m){
            while(tp>1 && cross(stk[tp]-stk[tp-1],pp[i]-stk[tp-1])<=0) tp--;
            stk[++tp]=pp[i];
        }
        printf("%d
    ",tp-1);
    }
    View Code
  • 相关阅读:
    Mac使用Homebrew进行软件包管理
    RNN模拟二进制加法
    虚拟机安装ubuntu18.04
    github合并分支到master
    Python配置虚拟环境
    Python的进程、线程、协程
    原码,反码,补码
    MySQL中的截位函数:RIGHT与LEFT
    MySQL查询和删除重复记录
    Mysql中的数据类型
  • 原文地址:https://www.cnblogs.com/1000Suns/p/10708817.html
Copyright © 2011-2022 走看看