1. 程式人生 > ><BZOJ3032>七夕祭

<BZOJ3032>七夕祭

urn scanf amp cstring 七夕 font imp 分享 stream

技術分享圖片
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,t;
long long ans=0;
int x[100010],y[100010],sumx[100010],sumy[100010];

int main()
{
    int i,xx,yy,arge;
    memset(x,0,sizeof(x));
    memset(y,0,sizeof
(y)); scanf("%d%d%d",&n,&m,&t); for(i=1;i<=t;i++)scanf("%d%d",&xx,&yy),x[xx]++,y[yy]++; if(t%n==0) { arge=t/n; sumx[0]=0; for(i=1;i<=n;i++)sumx[i]=sumx[i-1]+x[i]-arge; sort(sumx+1,sumx+n+1); arge=sumx[(n+1)/2
]; for(i=1;i<=n;i++)ans+=abs(arge-sumx[i]); } if(t%m==0) { arge=t/m; sumy[0]=0; for(i=1;i<=m;i++)sumy[i]=sumy[i-1]+y[i]-arge; sort(sumy+1,sumy+m+1); arge=sumy[(m+1)/2]; for(i=1;i<=m;i++)ans+=abs(arge-sumy[i]); }
if((t%n==0) && (t%m==0)) printf("both %lld\n",ans);else { if(t%n==0) printf("row %lld\n",ans);else { if(t%m==0) printf("column %lld\n",ans);else {printf("impossible\n");return 0;} } } return 0; }
醜陋のcode

<BZOJ3032>七夕祭