Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
there are 4 ways of partitioning in total, but i only find 3 in your codeIn Reply To:Re:i think perhaps you have missed some cases Posted by:Windows2k at 2005-06-04 12:55:06 > #include <cstring> > #include <cstdio> > using namespace std; > #define _int64 long long int > _int64 a[501][501],b[501][501]; > _int64 abs(_int64 a) { return (a>0) ? a : -a; } > int m,n; > int main() > { > while(scanf("%d %d",&m,&n)==2) { > if(!m&&!n) break; > _int64 min=(_int64)65535*500*500; > for(int i=1;i<=m;i++) > for(int j=1;j<=n;j++) scanf("%lld",&a[i][j]); > for(int i=1;i<=m;i++) > for(int j=1;j<=n;j++) b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j]; > for(int i=1;i<m;i++) > for(int j=1;j<n;j++) { > _int64 x=b[i][j],y=b[m][j]-b[i][j], > z=b[m][n]-b[m][j]; > _int64 t=abs(x-y)+abs(y-z)+abs(z-x); > if(t<min) min=t; > /*x=b[i][j],y=b[m][n]-b[m][j],z=b[m][j]-b[i][j]; > t=abs(x-y)+abs(y-z)+abs(z-x); > if(t<min) min=t;*/ > } > for(int i=1;i<m-1;i++) > for(int j=i+1;j<m;j++) { > _int64 x=b[i][n],y=b[j][n]-b[i][n],z=b[m][n]-b[j][n]; > _int64 t=abs(x-y)+abs(y-z)+abs(z-x); > if(t<min) min=t; > } > for(int i=1;i<n-1;i++) > for(int j=i+1;j<n;j++) { > _int64 x=b[m][i],y=b[m][j]-b[m][i],z=b[m][n]-b[m][j]; > _int64 t=abs(x-y)+abs(y-z)+abs(z-x); > if(t<min) min=t; > } > printf("%lld\n",min); > } > } > -- > Still GET WA :( Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator