bzoj3032: 七夕祭
那么这题实际上就是环形均分纸牌。。。那么就是糖果传递。。。
德国输了心态崩了。。。
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; int n,m,T; LL X[110000],Y[110000],s[110000]; LL reX() { LL ave=T/n; for(int i=1;i<=n;i++)s[i]=s[i-1]+ave-X[i]; sort(s+1,s+n+1); LL ret=0; for(int i=1;i<=n;i++) ret+=abs(s[i]-s[(n+1)/2]); return ret; } LL reY() { LL ave=T/m; for(int i=1;i<=m;i++)s[i]=s[i-1]+ave-Y[i]; sort(s+1,s+m+1); LL ret=0; for(int i=1;i<=m;i++) ret+=abs(s[i]-s[(m+1)/2]); return ret; } int main() { int x,y; scanf("%d%d%d",&n,&m,&T); for(int i=1;i<=T;i++) scanf("%d%d",&x,&y), X[x]++, Y[y]++; if(T%n==0&&T%m==0)printf("both %lld\n",reX()+reY()); else if(T%n==0)printf("row %lld\n",reX()); else if(T%m==0)printf("column %lld\n",reY()); else printf("impossible\n"); return 0; }
pain and happy in the cruel world.