解题思路:只有有奇数个1的行的个数和列的个数相同且为1才能只修改一个元素使其符合条件
注意事项:
参考代码:
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int odd1row = 0;
int odd1col = 0;
int changerow = 0, changecol = 0;
int n = 0;
cin >> n;
int** matrix = new int*[n];
for (int i = 0; i < n; i++)
{
matrix[i] = new int[n];
}
int* row = new int[n];
int* col = new int[n];
for (int i = 0; i < n; i++)
{
row[i] = 0;
col[i] = 0;
}
for (int i = 0; i < n; i++)
{
for (int I = 0; I < n; I++)
{
cin >> matrix[i][I];
if (matrix[i][I] == 1)
{
row[i] ++;
col[I] ++;
}
}
}
for (int i = 0; i < n; i++)
{
if (0 != row[i] % 2)
{
odd1row++;
changerow = i + 1;
}
if (0 != col[i] % 2)
{
odd1col++;
changecol = i + 1;
}
}
if (0 == odd1row && 0 == odd1col)
{
cout << "OK" << endl;
}
else if (1 < odd1row || 1 < odd1col || odd1row != odd1col)
{
cout << "Corrupt" << endl;
}
else
{
cout << changerow << " " << changecol << endl;
}
return 0;
}
0.0分
12 人评分