忽然觉得这个题很有必要写题解。
移项
y-x^2 = bx+c
那么其实就是找有多少条直线上方没有点
所以就是一个上凸壳有多少条直线/点.
绝妙啊!!!!
太妙了啊!!!!
神乎其技卧槽!!!
(我是傻逼)
1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 #include <vector> 5 #include <set> 6 using namespace std; 7 typedef long long db; 8 const double eps=1e-6; 9 const double pi=acos(-1); 10 int sign(db k){ 11 if (k>eps) return 1; else if (k<-eps) return -1; return 0; 12 } 13 int cmp(db k1,db k2){return sign(k1-k2);} 14 struct point{ 15 db x,y; 16 point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};} 17 point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};} 18 point operator * (db k1) const{return (point){x*k1,y*k1};} 19 point operator / (db k1) const{return (point){x/k1,y/k1};} 20 bool operator == (const point &k1) const{return cmp(x,k1.x)==0&&cmp(y,k1.y)==0;} 21 bool operator <(const point &k1)const { 22 int c=cmp(x,k1.x); 23 if(c)return c==-1; 24 return cmp(y,k1.y)==-1; 25 } 26 }; 27 db cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;} 28 db dot(point k1,point k2){return k1.x*k2.x+k1.y*k2.y;} 29 int n; 30 vector<point> convexHull(vector<point> ps){ 31 int n = ps.size();if(n<=1)return ps; 32 sort(ps.begin(),ps.end()); 33 vector<point> qs(n*2);int k=0; 34 for(int i=0;i<n;qs[k++]=ps[i++]) 35 while (k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-2])<=0)--k; 36 for(int i=n-2,t=k;i>=0;qs[k++]=ps[i--]) 37 while (k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-2])<=0)--k; 38 qs.resize(k-1); 39 return qs; 40 } 41 void getUDP(vector<point>A,vector<point>&U,vector<point>&D){ 42 db l=1e7,r=-1e7; 43 for (int i=0;i<A.size();i++) l=min(l,A[i].x),r=max(r,A[i].x); 44 int wherel,wherer; 45 for (int i=0;i<A.size();i++) if (cmp(A[i].x,l)==0) wherel=i; 46 for (int i=A.size();i;i--) if (cmp(A[i-1].x,r)==0) wherer=i-1; 47 U.clear(); D.clear(); int now=wherel; 48 while (1){D.push_back(A[now]); if (now==wherer) break; now++; if (now>=A.size()) now=0;} 49 now=wherel; 50 while (1){U.push_back(A[now]); if (now==wherer) break; now--; if (now<0) now=A.size()-1;} 51 } 52 vector<point>p,u,d; 53 db x,y; 54 int main(){ 55 scanf("%d",&n); 56 db mx=0; 57 for(int i=1;i<=n;i++){ 58 scanf("%lld%lld",&x,&y); 59 p.push_back(point{x,y-x*x}); 60 mx+=x; 61 } 62 p=convexHull(p); 63 getUDP(p,u,d); 64 set<int>s; 65 for(auto p:u)s.insert(p.x); 66 printf("%d\n",s.size()-1); 67 }View Code