CF1284E New Year and Castle Construction

Surface problem: https://codeforces.com/problemset/problem/1284/E
Solution:
Consider a quintuple formation of the convex hull.
Since the three points are not collinear, and therefore there can be only three scenarios:
1. There are three projection points comprising: contribution case 2;
2 protrusion comprises four points: Contribution to 1;
3. 5 with projecting points : 0 contribution.
The number of set three cases were \ (x_3 \) , \ (X_4 \) , \ (x_5 \) ,
then the answer is 2 \ (x_3 \) + \ (X_4 \) .
This thing is very good demand, regardless of conversion.
First discovered \ (X_3 \) + \ (X_4 \) + \ (x_5 \) = \ (C (n-,. 5) \)
Next, determine if found. 3 \ (X_3 \) +4 \ (X_4 \) +5 \ (x_5 \) ,
then the answer is very easy to find. Geometric meaning of this formula is the
\ (\ sum \) the number of the convex hull of each edge is located.
This thing can be obtained with a double pointer.
Time complexity: O ( \ (n-2 ^ \) logN)
Code:

#include<bits/stdc++.h>
using namespace std;
#define re register ll
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline ll
#define STS system("pause")
template<class D>I read(D &res){
    res=0;register D g=1;register char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-')g=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        res=(res<<3)+(res<<1)+(ch^48);
        ch=getchar();
    }
    res*=g;
}
typedef pair<ll,ll>pii;
struct Vec{
    ll x,y;
    Vec(ll _x=0,ll _y=0){x=_x;y=_y;}
    friend Vec operator + (Vec a,Vec b){return Vec(a.x+b.x,a.y+b.y);}
    friend Vec operator - (Vec a,Vec b){return Vec(a.x-b.x,a.y-b.y);}
    friend ll operator ^ (Vec a,Vec b){return a.x*b.y-a.y*b.x;}
    friend bool operator < (Vec a,Vec b){
        pii A=make_pair(a.x,a.y),B=make_pair(b.x,b.y);
        bool c=A<make_pair(0ll,0ll),d=B<make_pair(0ll,0ll);
        return c==d?(a^b)>=0:c<d;
    }
}p[2550];
vector<Vec>v;
ll n,m,ans,cnt;
IN C(ll x,ll y){
    re res=1;
    F(i,0,y-1){res*=(x-i);res/=(i+1);}
    return res;
}
int main(){
    read(n);
    F(i,1,n)read(p[i].x),read(p[i].y);
    F(i,1,n){
        v.clear();
        F(j,1,n){
            if(i==j)continue;
            v.emplace_back(p[j]-p[i]);
        }       
        sort(v.begin(),v.end());
        m=0;
        F(j,0,v.size()-1){
            while(m<j+v.size()&&(v[j]^v[m%v.size()])>=0)m++;
            cnt+=C(m-j-1,3);
        }
    }
    ans=C(n,5)*5ll-cnt;
    cout<<ans;
    return 0;
}

Guess you like

Origin www.cnblogs.com/Purple-wzy/p/12152663.html