Codeforces Round #420 (Div. 2) - A
题目链接:http://codeforces.com/contest/821/problem/A
题意:给定一个n*n的矩阵。 问你这个矩阵是否满足矩阵里的元素除了1以外,其他元素都可以在该元素的行和列分别找一个数然后相加等于它自身。
思路:按照题意暴力判断即可。
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<queue> #include<vector> #include<time.h> #include<cmath> using namespace std; typedef long long int LL; const LL INF = 9223372036854775807; const int MAXN = 50 + 24; int val[MAXN][MAXN]; int main(){ //#ifdef kirito // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); //#endif // int start = clock(); int n; while (~scanf("%d",&n)){ for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ scanf("%d", &val[i][j]); } } bool flag = true; for (int i = 0; i < n&&flag; i++){ for (int j = 0; j < n&&flag; j++){ if (val[i][j] == 1){ continue; } bool k = false; for (int xi = 0; xi < n; xi++){ for (int xj = 0; xj < n; xj++){ if (val[i][j] == val[i][xj] + val[xi][j]){ k = true; break; } } } if (k == false){ flag = false; } } } printf(flag ? "Yes\n" : "No\n"); } //#ifdef LOCAL_TIME // cout << "[Finished in " << clock() - start << " ms]" << endl; //#endif return 0; }