QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#756184#9520. Concave HullANIG#Compile Error//C++145.1kb2024-11-16 19:18:512024-11-16 19:18:53

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 19:18:53]
  • 评测
  • [2024-11-16 19:18:51]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
using E=long long;
const int inf=8e18;

struct vec{
    int x,y;
    vec(int a=0,int b=0){
        x=a,y=b;
    }
};

vec operator + (const vec &X,const vec &Y){
    return vec(X.x+Y.x,X.y+Y.y);
}

vec operator - (const vec &X,const vec &Y){
    return vec(X.x-Y.x,X.y-Y.y);
}

int cross(const vec &X,const vec &Y){
    return X.x*Y.y-X.y*Y.x;
}

int sgn(int x){
    if(x<0) return -1;
    if(x>0) return 1;
    return 0;
}

int area(const vec &X,const vec &Y,const vec &Z){
    return abs(X.x*Y.y+Y.x*Z.y+Z.x*X.y-X.x*Z.y-Y.x*X.y-Z.x*Y.y);
}

bool cmp(const vec &X,const vec &Y){
    if(sgn(X.x-Y.x)) return X.x<Y.x;
    return X.y<Y.y;
}

void solve(){

    int n;
    cin>>n;
    vector<vec> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i].x>>a[i].y;
    }

    sort(a.begin(),a.end(),cmp);

    vector<int> z;
    for(int i=0; i<n; i++){
        while(z.size()>1&&cross(a[z.back()]-a[z[z.size()-2]],a[i]-a[z[z.size()-2]])<=0) z.pop_back();
        z.emplace_back(i);    
    }
    int k=z.size();
    for(int i=n-2; i>=0; i--){
        while(z.size()>k&&cross(a[z.back()]-a[z[z.size()-2]],a[i]-a[z[z.size()-2]])<=0) z.pop_back();
        z.emplace_back(i);
    }
    if(n>1) z.pop_back();

    vector<int> used(n);
    for(auto p:z){
        used[p]=1;
        //cerr<<"convex "<<a[p].x<<' '<<a[p].y<<endl;
    }

    int ans=inf;
    vector<pair<int,int>> P;
    for(int i=0; i<n; i++){
        if(!used[i]){
            P.emplace_back(a[i].x,a[i].y);
        }
    }

    if(!P.size()){
        cout<<-1<<'\n';
        return ;
    }
    
    auto getpos=[&](int k1,int b1,int k2,int b2)->int{
        return (b2-b1)/(k1-k2);
    };

    sort(P.begin(),P.end());
    vector<pair<int,int>> Tmp;
    int mx=-inf;
    for(auto p:P){
        if(Tmp.size()==0||p.second<Tmp.back().second){
            while(Tmp.asize()>1&&getpos(p.first,p.second,Tmp[Tmp.size()-2].first,Tmp[Tmp.size()-2].second)<
            getpos(Tmp.back().first,Tmp.back().second,Tmp[Tmp.size()-2].first,Tmp[Tmp.size()-2].second)) Tmp.pop_back();
            Tmp.emplace_back(p);
        }
        mx=max(mx,p.second);
    }
    swap(Tmp,P);

    vector<array<int,3>> T;

    auto add=[&](int x,int y,int z)->void{
        if(y==0){
            ans=min(ans,mx*x+z);
            //cerr<<ans<<endl;
            return ;
        }
        T.emplace_back(array<int,3>({x,y,z}));
    };

    for(int i=0; i+1<z.size(); i++){
        add(a[z[i]].y-a[z[i+1]].y,
        a[z[i+1]].x-a[z[i]].x,
        a[z[i]].x*a[z[i+1]].y-a[z[i+1]].x*a[z[i]].y);
    }
    add(a[z.back()].y-a[z[0]].y,
    a[z[0]].x-a[z.back()].x,
    a[z.back()].x*a[z[0]].y-a[z[0]].x*a[z.back()].y);

    sort(P.begin(),P.end(),greater<>());
    
    vector<array<int,3>> T1,T2;
    for(auto &pt:T){
        if(pt[1]>0){
            T1.emplace_back(pt);
        }
        else T2.emplace_back(pt);
    }

    sort(T1.begin(),T1.end(),[&](auto &X,auto &Y){ return X[0]*Y[1]<X[1]*Y[0]; });

    int pnt=0;
    for(auto &pt:T1){
        while(pnt+1<P.size()&&pt[0]*P[pnt].first+pt[1]*P[pnt].second
        >pt[0]*P[pnt+1].first+pt[1]*P[pnt+1].second){
            pnt++;
        }
        //cerr<<"at "<<pt[0]<<' '<<pt[1]<<' '<<pt[2]<<' '<<P[pnt].first<<' '<<P[pnt].second<<endl;
        //cerr<<pt[0]*P[pnt].first+pt[1]*P[pnt].second+pt[2]<<endl;
        ans=min(ans,pt[0]*P[pnt].first+pt[1]*P[pnt].second+pt[2]);
    }

    swap(Tmp,P);
    Tmp.clear();
    sort(P.begin(),P.end(),greater<>());
    for(auto p:P){
        if(Tmp.size()==0||p.second>Tmp.back().second){
            while(Tmp.size()>1&&getpos(p.first,p.second,Tmp[Tmp.size()-2].first,Tmp[Tmp.size()-2].second)<
            getpos(Tmp.back().first,Tmp.back().second,Tmp[Tmp.size()-2].first,Tmp[Tmp.size()-2].second)) Tmp.pop_back();
            Tmp.emplace_back(p);
        }
        mx=max(mx,p.second);
    }
    swap(Tmp,P);

    sort(T2.begin(),T2.end(),[&](auto &X,auto &Y){ return X[0]*Y[1]>X[1]*Y[0]; });
    pnt=0;
    for(auto &pt:T2){
        while(pnt+1<P.size()&&pt[0]*P[pnt].first+pt[1]*P[pnt].second
        >pt[0]*P[pnt+1].first+pt[1]*P[pnt+1].second){
            pnt++;
        }
        /*
        for(auto x:P){
            //cerr<<x.first<<','<<x.second<<' ';
            cerr<<pt[0]*x.first+pt[1]*x.second+pt[2]<<' ';
        }
        cerr<<endl;*/
        //cerr<<"at "<<pt[0]<<' '<<pt[1]<<' '<<pt[2]<<' '<<P[pnt].first<<' '<<P[pnt].second<<endl;
        //cerr<<pt[0]*P[pnt].first+pt[1]*P[pnt].second+pt[2]<<endl;
        ans=min(ans,pt[0]*P[pnt].first+pt[1]*P[pnt].second+pt[2]);
    }

    ans=-ans;
    cerr<<ans<<'\n';
    for(int i=2; i<z.size(); i++){
        ans+=area(a[z[i]],a[z[i-1]],a[z[0]]);
    }

    cout<<ans<<'\n';

}

/*

1
6
-2 0
1 -2
5 2
0 4
1 2
3 1
convex -2 0
convex 1 -2
convex 5 2
convex 0 4
at 4 -2 8 1 2
at -4 4 12 1 2
at -2 -5 20 1 2
at 2 3 4 1 2
36

1
4
0 0
1 0
0 1
1 1

*/

signed main(){

    cin.tie(0),cout.tie(0)->sync_with_stdio(false);

    int T;
    cin>>T;
    while(T--) solve();

    return 0;
}

详细

answer.code: In function ‘void solve()’:
answer.code:92:23: error: ‘class std::vector<std::pair<long long int, long long int> >’ has no member named ‘asize’; did you mean ‘size’?
   92 |             while(Tmp.asize()>1&&getpos(p.first,p.second,Tmp[Tmp.size()-2].first,Tmp[Tmp.size()-2].second)<
      |                       ^~~~~
      |                       size