//228K 16MS C++#include <cstdio>#include <cstring>using namespace std;int map[105][105];int size;int RowSum[105];int ColumnSum[105];void solve() { memset(RowSum, 0, sizeof(RowSum)); memset(ColumnSum, 0, sizeof(ColumnSum)); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { RowSum[y] += map[y][x]; ColumnSum[x] += map[y][x]; } } int oddRowNum = 0; int oddRowId = -1; int oddColumnNum = 0; int oddColumnId = -1; for (int rowId = 0; rowId < size; rowId++) { if (RowSum[rowId]%2) { oddRowId = rowId; oddRowNum++; } } for (int columnId = 0; columnId < size; columnId++) { if (ColumnSum[columnId]%2) { oddColumnId = columnId; oddColumnNum++; } } if (!oddRowNum && !oddColumnNum) { printf("OK\n"); } else if (oddRowNum == 1 && oddColumnNum ==1) { printf("Change bit (%d,%d)\n", oddRowId + 1, oddColumnId + 1); } else { printf("Corrupt\n"); }}int main() { while(scanf("%d", &size) != EOF) { if (size == 0) { return 0; } memset(map, 0, sizeof(map)); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { scanf("%d", &(map[y][x])); } } solve(); }}
虽然是水题,但做的时候并不清楚,一开始还做了两个循环,去遍历所有row和column的组合,然后判断什么的,
后来才发现自己的经历可以满足题目的需求。。。思维本身就有问题。.
数组开小WA好几次了
我觉得深入研究这类问题还是有学问的。. 矩阵应该是相关的.