社区讨论

23pts 求调

P8101 [USACO22JAN] Multiple Choice Test P参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mhj1pbr1
此快照首次捕获于
2025/11/03 19:17
4 个月前
此快照最后确认于
2025/11/03 19:17
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Point{
    ll x, y;
    Point operator+(const Point &p) const {return {x+p.x, y+p.y};}
    Point operator-(const Point &p) const {return {x-p.x, y-p.y};}
    ll operator*(const Point &p) const {return x*p.y-y*p.x;}
    bool operator<(const Point &p) const {return x^p.x?x<p.x:y<p.y;}
};
vector<Point> convex(vector<Point> p){
    int n = p.size();
    sort(p.begin(), p.end());
    vector<Point> ans;
    vector<int> st;
    vector<bool> used(n);
    st.push_back(0);
    for(int i=1;i<n;i++){
        while(st.size()>=2&&(p[st.back()]-p[st[st.size()-2]])*(p[i]-p[st.back()])<=0) used[st.back()]=0, st.pop_back();
        st.push_back(i);
        used[i] = 1;
    }
    int tmp = st.size();
    for(int i=n-1;i>=0;i--){
        if (used[i]) continue;
        while(st.size()>tmp&&(p[st.back()]-p[st[st.size()-2]])*(p[i]-p[st.back()])<=0) used[st.back()]=0, st.pop_back();
        st.push_back(i);
        used[i] = 1;
    }
    for(auto i:st) ans.push_back(p[i]);
    ans.pop_back();
    return ans;
}
vector<Point> sum(vector<vector<Point>> p){
    vector<Point> c{{0,0}};
    for(auto v:p){
        ll x=v[0].x, y=v[0].y;
        //for(int i=1;i<v.size();i++)v[i].y < y ? x=v[i].x, y=v[i].y : x = min(x, v[i].x);
        c[0].x+=x, c[0].y+=y;
        for(int i=0;i+1<v.size();i++) v[i]=v[i+1]-v[i];
        v.pop_back();
        for(auto i:v) c.push_back(i);
    }
    //cout << "SIZE IS " << c.size() << '\n';
    sort(c.begin()+1, c.end(), [](const Point &a, const Point &b){
        ll cross = a * b;
        if (cross) return cross > 0;
        return a.x > b.x;
    });
    for(int i=1;i<c.size();i++) c[i]=c[i-1]+c[i];
    return c;
}
int n, g;
ll ans;
vector<vector<Point>> p;
vector<Point> q;

int main(){
    cin>>n;
    p.resize(n);
    for(int i=0;i<n;i++){
        cin>>g;
        p[i].resize(g);
        for(int j=0;j<g;j++) cin>>p[i][j].x>>p[i][j].y;
        p[i] = convex(p[i]);
        //cout << i << '\n';
        //for(auto [x,y]:p[i]) cout << x << ' ' << y << '\n';
    }
    q = sum(p);
    for(auto [x, y]:q) ans = max(ans, x*x+y*y);
    cout << ans;
}
仅 AC #1,#6,#7,#8

回复

0 条回复,欢迎继续交流。

正在加载回复...