Codeforces Round #549 (Div. 2)F. U2(计算几何凸壳)

F. U2

题意:

输入 n ( 1 e 5 ) n(1e5) n(1e5)
接下来输入 n n n行,每行 x , y ( 1 e 6 ) x,y(1e6) x,y(1e6)表示一个点。
在平面任意两点都画一个二次函数 y = x 2 + b x + c y=x^2+bx+c y=x2+bx+c,问有多少个二次函数使其它的点不在它内部。

题解:

y = y 2 − x y=y^2-x y=y2x,那么方程就变成了 y = b x + c y=bx+c y=bx+c,变成了一条直线,使其它经过变换的点都在它下面,其实就变成了求凸包上壳问题。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+9;
#define ll long long
#define P pair<ll,ll>
P a[N];int n;
bool cmp(P p1,P p2){
    if(p1.first!=p2.first)return p1.first<p2.first;
    return p1.second>p2.second;
}
int q[N],hd,tl;
int main(){
    //freopen("tt.in","r",stdin),freopen("tt.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second,a[i].second=a[i].second-a[i].first*a[i].first;
    sort(a+1,a+n+1,cmp);
    int hd=0,tl=-1;
    for(int i=1;i<=n;i++){
        if(tl!=-1&&a[q[tl]].first==a[i].first)continue;
        while(tl>0&&(a[i].second-a[q[tl]].second)*(a[q[tl]].first-a[q[tl-1]].first)>=(a[i].first-a[q[tl]].first)*(a[q[tl]].second-a[q[tl-1]].second))tl--;
        q[++tl]=i;
    }
    cout<<tl<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值