题意:询问n X n中非1数是否能够由同行同列中分别取两个数做和得到。
思路:水题。
/** @Date : 2017-07-03 16:23:18 * @FileName: A.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/stdc++.h> #define LL long long #define PII pair #define MP(x, y) make_pair((x),(y)) #define fi first #define se second #define PB(x) push_back((x)) #define MMG(x) memset((x), -1,sizeof(x)) #define MMF(x) memset((x),0,sizeof(x)) #define MMI(x) memset((x), INF, sizeof(x)) using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5+20; const double eps = 1e-8; int n; int a[60][60]; int main() { while(cin >> n) { for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) scanf("%d", &a[i][j]); } int ans = 1; for(int i = 1; i <= n && ans; i++) { for(int j = 1; j <= n && ans; j++) { if(a[i][j] == 1) continue; int flag = 1; for(int k = 1; k <= n; k++) { if(j == k || a[i][k] >= a[i][j]) continue; if(!flag) break; for(int l = 1; l <= n; l++) { if(!flag) break; if(l == i || a[i][k] + a[l][j] != a[i][j]) continue; else { flag = 0; break; } } } if(flag) { //cout << i << j << endl; ans = 0; break; } } } printf("%s\n", ans?"Yes":"No"); } return 0; }
时间: 2024-12-18 06:28:05