#include <iostream>
using namespace std;
#define MAX 200
#define cls(x) memset(x, false, sizeof(x))
bool map[MAX][MAX];
bool gold[MAX][MAX];
int mr, mc, sr, sc;
char Input[MAX];
void ChangMap(int i, int j)
{
for (int ti = 0; ti < sr; ++ti)
for (int tj = 0; tj < sc; ++tj)
map[i + ti][j + tj] = !map[i + ti][j + tj];
}
bool CanSolve()
{
for (int i = 0; i < mr; ++i)
for (int j = 0; j < mc; ++j)
if (map[i][j] != gold[i][j])
return false;
return true;
}
int main()
{
while (cin >> mr >> mc >> sr >> sc)
{
if (mr == 0 && mc == 0 && sr == 0 && sc == 0) break;
cls(map);
cls(gold);
//for (int i = 0; i < mr; ++i)
// for (int j = 0; j < mc; ++j)
// cin >> gold[i][j];
for (int i = 0; i < mr; ++i)
{
cin >> Input;
for (int j = 0; j < mc; ++j)
gold[i][j] = (Input[j] == '0' ? false : true);
}
int step = 0;
for (int i = 0; i < mr - sr + 1; ++i)
for (int j = 0; j < mc - sc + 1; ++j)
{
if (map[i][j] != gold[i][j])
{
ChangMap(i, j);
step++;
}
}
if (CanSolve()) cout << step << endl;
else cout << "-1\n";
}
return 0;
}
HDU 1801
最新推荐文章于 2017-08-04 01:07:52 发布