CodeFroces 821A Okabe and Future Gadget Laboratory

来源:互联网 发布:python 使用相对路径 编辑:程序博客网 时间:2024/06/05 15:57

http://codeforces.com/problemset/problem/821/A

题意很简单,就是说一个n*n的矩阵中是否有不为1的数字是无法从同一行的一个数字+同一列的一个数字加起来,如果存在这样的数字输出no,否则输出yes。

You can output each letter in upper or lower case.

代码如下:

#include<bits/stdc++.h>using namespace std;int n, G[55][55];bool Check(int x, int y){for(int i = 0; i < n; i++){for(int j = 0; j < n; j++){if(y == i || x == j)continue;if(G[x][i] + G[j][y] == G[x][y])return 1;}}return 0;}int main(){bool flag = 1;cin >> n;for(int i = 0; i < n; i++)for(int j = 0; j < n; j++)cin >> G[i][j];for(int i = 0; i < n; i++)for(int j = 0; j < n; j++){if(G[i][j] != 1){if(!Check(i, j)){flag = 0;//cout << i << " " << j << endl;}}}if(flag)cout << "Yes" << endl;elsecout << "No" << endl;return 0;}