• The Preliminary Contest for ICPC Asia Xuzhou 2019 K. Center


    题目链接:https://nanti.jisuanke.com/t/41393

    题目大意:给出n个点,问最少加多少点使得这些点中心对称。

    题解:

    两个点可以确定一个中心点,O(n^2)枚举中心点,设cnt[Xc][Yc]为中心点(Xc,Yc)被枚
    举到次数,
    那么对于中心点(Xc,Yc),需要补上的点的个数为n-2*cnt[Xc][Yc]-(点(Xc,Yc)在原来
    的点集里出现的次数),
    可以用map或者哈希记录cnt的值。
    另外,如果把输入的坐标都乘以2,那么枚举到的中心点的坐标就都是整数了。
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    struct st{
        ll x,y;
    }stm[1005];
    map<ll,int> mp;
    map<ll,int> mp1;
    set<ll> se;
    const ll tem=1e7;
    queue<ll> que;
    map<ll,int> vis;
    int main(){
        int n;
        scanf("%d",&n);
        int maxs=0;
        for(int i=0;i<n;i++){
            scanf("%lld%lld",&stm[i].x,&stm[i].y);
            stm[i].x*=2;
            stm[i].y*=2;
            ll tt=stm[i].x*tem+stm[i].y;
            mp[tt]++;
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i<j){
                    ll tt=(stm[i].x+stm[j].x)/2*tem+(stm[i].y+stm[j].y)/2;
                    int count=++mp1[tt];
                    if(count>maxs){
                        maxs=count;
                        while(!que.empty())que.pop();
                        que.push(tt);
                    }
                    else if(count==maxs){
                        que.push(tt);
                    }
                }      
            }
        }
        int ans=n;
       
        while(!que.empty()){
            ll tt=que.front();
            que.pop();
            ans=min(ans,n-mp1[tt]*2-(mp[tt]&1));
            if(mp[tt]&1)break;
        //    cout<<tt<<endl;
        }
        for(int i=0;i<n;i++){//考虑中心点在原点的情况 
            ll tt=stm[i].x*tem+stm[i].y;
            ans=min(ans,n-mp1[tt]*2-(mp[tt]&1));
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    构建之法阅读笔记04
    学习进度条10
    描绘用户场景并将典型用户和用户场景描述
    学习进度条09
    构建之法阅读笔记03
    学习进度条08
    每日站立会议10(完成)
    每日站立会议09
    团队成员细节工作项估计
    JS实现全选、不选、反选
  • 原文地址:https://www.cnblogs.com/Zhi-71/p/11489392.html
Copyright © 2020-2023  润新知