poj2260

简单题

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;

#define maxn 105

int n;
int sum_row[maxn];
int sum_col[maxn];
int f[maxn][maxn];

void input()
{
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            scanf("%d", &f[i][j]);
}

void count_odd(int* sum, int &cnt, int &ans)
{
    for (int i = 0; i < n; i++)
        if (sum[i] & 1)
        {
            cnt++;
            ans = i;
        }
}

void work()
{
    memset(sum_col, 0, sizeof(sum_col));
    memset(sum_row, 0, sizeof(sum_row));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            sum_row[i] += f[i][j];
            sum_col[j] += f[i][j];
        }
    int cnt_col, cnt_row;
    cnt_col = cnt_row = 0;
    int ans_col, ans_row;
    count_odd(sum_row, cnt_row, ans_row);
    count_odd(sum_col, cnt_col, ans_col);
    if (cnt_col == 0 && cnt_row == 0)
    {
        puts("OK");
        return;
    }
    if (cnt_row > 1 || cnt_col > 1 || cnt_col != cnt_row)
    {
        puts("Corrupt");
        return;
    }
    printf("Change bit (%d,%d)\n", ans_row + 1, ans_col + 1);
}

int main()
{
    while (scanf("%d", &n), n)
    {
        input();    
        work();
    }
    return 0;
}
View Code

 

posted @ 2013-06-08 19:39  undefined2024  阅读(169)  评论(0编辑  收藏  举报