Lydsy3032 七夕祭(货仓选址+均分纸牌结合)
Posted lmjer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lydsy3032 七夕祭(货仓选址+均分纸牌结合)相关的知识,希望对你有一定的参考价值。
环形均分纸牌
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; const int maxn=100000+10; ll heng[maxn],shu[maxn]; ll sum[maxn]; ll getans(ll a[maxn],int n){ ll k=a[0]/n; for (int i=1;i<=n;i++){ a[i]=a[i]-k; sum[i]=sum[i-1]+a[i]; } ll ans=0; sort(sum+1,sum+1+n); for (int i=1;i<=n;i++) ans+=abs(sum[i]-sum[n+1>>1]); return ans; } int main(){ int m,n,t; int u,v; scanf("%d%d%d",&n,&m,&t); for (int i=1;i<=t;i++){ scanf("%d%d",&u,&v); heng[u]++; shu[v]++; } for (int i=1;i<=n;i++) heng[0]+=heng[i]; for (int i=1;i<=m;i++) shu[0]+=shu[i]; if(heng[0]%n==0&&shu[0]%m==0){ printf("both %lld\n",getans(heng,n)+getans(shu,m)); } else if(heng[0]%n==0){ printf("row %lld\n",getans(heng,n)); } else if(shu[0]%m==0){ printf("column %lld\n",getans(shu,m)); } else printf("impossible\n"); return 0; }
以上是关于Lydsy3032 七夕祭(货仓选址+均分纸牌结合)的主要内容,如果未能解决你的问题,请参考以下文章