计算几何小结计算几何小结

计算几何小结

计算几何是个好东西,写代码感觉在写LemonLime(不你没真正写过),一层层堆叠起来,真(难)好(调)玩。

占坑

//@winlere
#include
#include
#include
#include
#include
#include
#include
#define pf(x) ((x)*(x))

using namespace std;  typedef long long ll;
inline int qr(){
    int ret=0,f=0,c=getchar();
    while(!isdigit(c))f|=c==45,c=getchar();
    while(isdigit(c)) ret=ret*10+c-48,c=getchar();
    return f?-ret:ret;
}

struct NODE{
    double x,y;
    NODE operator + (NODE b)const{return {x+b.x,y+b.y};}
    NODE operator - (NODE b)const{return {x-b.x,y-b.y};}
    NODE operator * (double b)const{return {x*b,y*b};}
    double operator % (NODE b)const{return x*b.y-y*b.x;}
    double operator ^ (NODE b)const{return sqrt(pf(x-b.x)+pf(y-b.y));}
    bool operator < (NODE b)const{return atan2(y,x)0:vec mat;
typedef vector poly;
poly data;
const double bound=1000;
double sum(poly data){
    if(data.size()<3) return 0;
    double ret=0;
    sort(data.begin(),data.end());
    NODE x={0,0};
    for(int t=0,ed=data.size();t q(data.begin(),data.begin()+2);
    for(int t=2,ed=data.size();t1){
            NODE m=q[q.size()-1]*q[q.size()-2];
            assert(m.x<=1e7);
            if(data[t].vec%(m-data[t].pt)<0) q.pop_back();
            else break;
        }
        while(q.size()>1){
            NODE m=q[0]*q[1];
            assert(m.x<=1e7);
            if(data[t].vec%(m-data[t].pt)<0) q.pop_front();
            else break;
        }
        q.push_back(data[t]);
    }
    while(q.size()>1){
        NODE m=q[q.size()-1]*q[q.size()-2];
        assert(m.x<=1e7);
        if(q.front().vec%(m-q.front().pt)<0) q.pop_back();
        else break;
    }
    while(q.size()>1){
        NODE m=q[0]*q[1];
        assert(m.x<=1e7);
        if(q.back().vec%(m-q.back().pt)<0) q.pop_front();
        else break;
    }
    return poly(q.begin(),q.end());
}

int main(){
    int n=qr();
    for(int t0=1;t0<=n;++t0){
        mat sav(qr());
        for(auto&t:sav) t.x=qr(),t.y=qr();
        for(int i=0,ed=sav.size();i

你可能感兴趣的:(计算几何小结计算几何小结)