关闭

zoj2835

260人阅读 评论(0) 收藏 举报
分类:
#include <iostream>
#include <fstream>
using namespace std;

bool IsHuanFang(int sum1, int sum2, int *Rsum, int *Csum, int n)
{
	int sum = 0;
	if (sum1 != sum2)
		return false;
	for (int i = 0; i < n; ++i)
	{
		if (sum1 != Rsum[i] || sum1 != Csum[i])
			return false;
		sum += Rsum[i];
	}
	if (sum == (Rsum[0] / n) * (Rsum[0] / n))
		return false;
	return true;
}
const int MAX = 15;
int main()
{
	ifstream cin("2835.txt");
	int a[MAX][MAX], n;
	int Rsum[MAX], Csum[MAX], sum1, sum2;
	while (cin >> n && n)
	{
		for (int i = 0; i < MAX; ++i)
			Rsum[i] = Csum[i] = 0;
		sum1 = sum2 = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				cin >> a[i][j];
				if (i == j)
					sum1 += a[i][j];
				if (i + j == n - 1)
					sum2 += a[i][j];
				Rsum[i] += a[i][j];
				Csum[j] += a[i][j];
			}
		}
		if (IsHuanFang(sum1, sum2, Rsum, Csum, n))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12401次
    • 积分:477
    • 等级:
    • 排名:千里之外
    • 原创:37篇
    • 转载:3篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档