【题目链接】https://codeforces.com/problemset/problem/1142/C
【题解】
考虑如何处理在抛物线内部。显然不好处理。
观察式子 $y=x^2+bx+c$,我们发现 $b$ 与 $x^2$ 无关。换句话说,最高只有一次项系数不确定。
因此可以考虑进行转化。令 $y‘=y-x^2$,则要求为在直线 $y‘=bx+c$ 上方无其余点。维护凸包即可。
效率 $O(n \log n)$。
1 #include<bits/stdc++.h> 2 struct Graph 3 { 4 struct Vector 5 { 6 long long x,y; 7 Vector(long long _x=0,long long _y=0){x=_x;y=_y;} 8 inline friend Vector operator - ( const Vector &u,const Vector &v ) { return Vector(u.x-v.x,u.y-v.y); } 9 inline friend long long operator ^ ( const Vector &u,const Vector &v ) { return u.x*v.y-u.y*v.x; } 10 }st[1000000];int tp; 11 std::vector<Vector> V,E; 12 inline void add ( long long x,long long y ) { V.push_back(Vector(x,y)); } 13 inline long long solve ( void ) 14 { 15 std::sort(V.begin(),V.end(),[&](const Vector &u,const Vector &v){return u.x==v.x ? u.y>v.y : u.x>v.x;}); 16 E.push_back(V[0]); 17 for ( int i=1;i<(int)V.size();i++ ) if ( V[i].x!=V[i-1].x ) E.push_back(V[i]); 18 for ( auto p:E ) 19 { 20 while ( tp>1 and ((p-st[tp-1])^(st[tp]-st[tp-1]))>=0 ) tp--; 21 st[++tp]=p; 22 } 23 return tp-1; 24 } 25 }G; 26 signed main() 27 { 28 int n;scanf("%d",&n); 29 for ( int i=1,x,y;i<=n;i++ ) scanf("%d%d",&x,&y),G.add(x,y-1LL*x*x); 30 return !printf("%lld\n",G.solve()); 31 }
原文:https://www.cnblogs.com/RenSheYu/p/12274190.html