# 【题解】打地鼠 SDOI2011 模拟 行列无关

### Code

#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
const int MAXN = 110;
int _w;

int n, m, a[MAXN][MAXN], tot;
int r, c, b[MAXN][MAXN];
int t[MAXN][MAXN];

bool check( int x ) {
for( int i = 1; i <= r; ++i )
for( int j = 1; j <= c; ++j )
t[i][j] = b[i][j];
for( int i = 1; i <= r; ++i )
for( int j = 1; j <= c-x+1; ++j )
for( int k = j+x-1; k >= j; --k )
t[i][k] -= t[i][j];
for( int i = 1; i <= r; ++i )
for( int j = 1; j <= c; ++j )
if( t[i][j] ) return false;
return true;
}

void solve() {
r = n, c = m;
for( int i = 1; i <= r; ++i )
for( int j = 1; j <= c; ++j )
b[i][j] = a[i][j];
for( int x = c; x >= 1; --x )
if( check(x) ) {
tot /= x;
break;
}
r = m, c = n;
for( int i = 1; i <= r; ++i )
for( int j = 1; j <= c; ++j )
b[i][j] = a[j][i];
for( int y = c; y >= 1; --y )
if( check(y) ) {
tot /= y;
break;
}
printf( "%d\n", tot );
}

int main() {
_w = scanf( "%d%d", &n, &m );
tot = 0;
for( int i = 1; i <= n; ++i )
for( int j = 1; j <= m; ++j ) {
_w = scanf( "%d", &a[i][j] );
tot += a[i][j];
}
solve();
return 0;
}`
posted @ 2017-12-20 20:14 mlystdcall 阅读(...) 评论(...) 编辑 收藏