A. Okabe and Future Gadget Laboratory
来源:互联网 发布:移动宽带看网络电视 编辑:程序博客网 时间:2024/06/05 19:31
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 ≤ x, y ≤ n and ax, y ≠ 1, there should exist two indices s and t so that ax, y = ax, s + at, y, where ai, j denotes the integer in i-th row and j-th column.
Help Okabe determine whether a given lab is good!
The first line of input contains the integer n (1 ≤ n ≤ 50) — the size of the lab.
The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is ai, j (1 ≤ ai, j ≤ 105).
Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case.
31 1 22 3 16 4 1
Yes
31 5 21 1 11 2 3
No
In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No".
解题说明:此题是一道模拟题,按照题目意思进行遍历找到符号条件的情况即可。
#include<cstdio>#include<algorithm>#include<cstring>#include<cstdlib>#include<iostream>using namespace std;int main() {static int aa[51][51];int n, i, j, x, y, s, t, good;scanf("%d", &n);for (i = 0; i < n; i++){for (j = 0; j < n; j++){scanf("%d", &aa[i][j]);}}for (x = 0; x < n; x++){for (y = 0; y < n; y++) {if (aa[x][y] == 1){continue;}good = 0;for (s = 0; s < n; s++){for (t = 0; t < n; t++){if (aa[x][s] + aa[t][y] == aa[x][y]){good = 1;break;}}}if (!good) {printf("No\n");return 0;}}}printf("Yes\n");return 0;}
- A. Okabe and Future Gadget Laboratory
- Okabe and Future Gadget Laboratory
- #420 A. Okabe and Future Gadget Laboratory(Div.2)
- Codeforces 821 A. Okabe and Future Gadget Laboratory
- Codeforces 821A-Okabe and Future Gadget Laboratory
- Codeforces 821A Okabe and Future Gadget Laboratory 题解
- CodeFroces 821A Okabe and Future Gadget Laboratory
- CF #420 A. Okabe and Future Gadget Laboratory
- CodeForces 821A Okabe and Future Gadget Laboratory
- Codeforces Round #420 A. Okabe and Future Gadget Laboratory
- CF821A-Okabe and Future Gadget Laboratory
- Codeforces821A Okabe and Future Gadget Laboratory
- Okabe and Future Gadget Laboratory CodeForces
- Codeforces Round #420 (Div. 2) A. Okabe and Future Gadget Laboratory
- #420 Div.2 A. Okabe and Future Gadget Laboratory——暴力
- CF Okabe and Boxes
- C. Okabe and Boxes
- Codeforces821C Okabe and Boxes
- caffe loss 损失权重问题
- 关于retrofit进行网络请求时发生的奇怪错误
- js图片点击转换
- C#基础知识
- android Sroll事件的一些坑
- A. Okabe and Future Gadget Laboratory
- T检验
- Mysql常用优化方案
- PHP中类的继承特性之方法的重载(覆盖)
- 设计模式(十八)composite
- struts2_标签、主题
- 仗剑走天涯
- 【Android】Splash的使用
- C++虚函数指针虚函数表