Codeforces 821A-Okabe and Future Gadget Laboratory
2017-06-26 22:55
543 查看
Okabe and Future Gadget Laboratory
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n byn 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!
Input
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).
Output
Print "Yes" if the given lab is good and "No"
otherwise.
You can output each letter in upper or lower case.
Examples
input
output
input
output
Note
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".
题意:给你一个n*n的矩阵,若矩阵内所有的方格满足a[i][j]!=1,并且a[i][j]等于它那一列一个数和它那一行一个数的和,则输出Yes,否则输出No
解题思路:暴力判断每个方格是否满足
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
int a[60][60];
int n;
int main()
{
while (~scanf("%d", &n))
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &a[i][j]);
int flag = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (a[i][j] == 1) continue;
int flag1 = 0;
for (int k = 1; k <= n; k++)
{
for(int p=1;p<=n;p++)
if (a[i][j] == a[i][k] + a[p][j]) { flag1 = 1; break; }
if (flag1) break;
}
if (!flag1) { flag = 0; break; }
}
if (!flag) break;
}
if (flag) printf("Yes\n");
else printf("No\n");
}
return 0;
}
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n byn 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!
Input
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).
Output
Print "Yes" if the given lab is good and "No"
otherwise.
You can output each letter in upper or lower case.
Examples
input
3 1 1 2 2 3 1 6 4 1
output
Yes
input
3 1 5 2 1 1 1 1 2 3
output
No
Note
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".
题意:给你一个n*n的矩阵,若矩阵内所有的方格满足a[i][j]!=1,并且a[i][j]等于它那一列一个数和它那一行一个数的和,则输出Yes,否则输出No
解题思路:暴力判断每个方格是否满足
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
int a[60][60];
int n;
int main()
{
while (~scanf("%d", &n))
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &a[i][j]);
int flag = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (a[i][j] == 1) continue;
int flag1 = 0;
for (int k = 1; k <= n; k++)
{
for(int p=1;p<=n;p++)
if (a[i][j] == a[i][k] + a[p][j]) { flag1 = 1; break; }
if (flag1) break;
}
if (!flag1) { flag = 0; break; }
}
if (!flag) break;
}
if (flag) printf("Yes\n");
else printf("No\n");
}
return 0;
}
相关文章推荐
- Okabe and Future Gadget Laboratory CodeForces - 821A
- Codeforces 821 A. Okabe and Future Gadget Laboratory
- CF821A-Okabe and Future Gadget Laboratory
- CF #420 A. Okabe and Future Gadget Laboratory
- Okabe and Future Gadget Laboratory
- A. Okabe and Future Gadget Laboratory
- #420 A. Okabe and Future Gadget Laboratory(Div.2)
- Okabe and Future Gadget Laboratory
- #420 Div.2 A. Okabe and Future Gadget Laboratory——暴力
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
- Codeforces Round #420 (Div. 2) A. Okabe and Future Gadget Laboratory
- codeforces 420 div2 C Okabe and Boxes
- Codeforces 821B-Okabe and Banana Trees
- Codeforces 821C-Okabe and Boxes
- 栈 Okabe and Boxes:CodeForces - 821C
- 【codeforces 821E】Okabe and El Psy Kongroo
- Codeforces 821 E. Okabe and El Psy Kongroo
- Codeforces 821 B. Okabe and Banana Trees
- codeforces 420-C. Okabe and Boxes
- codeforces 821 B Okabe and Banana Trees