Round #420 A. Okabe and Future Gadget Laboratory(Div.2)
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.
3
1 1 2
2 3 1
6 4 1
Yes
3
1 5 2
1 1 1
1 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".
想明白后才发现,答案原来题目中已有,笑哭呀,还是要好好听老师说的话,好好读题,答案就在题中。
题意:有一个n×n的格子,格子里面的数如果大于1,那么它就必须等于它所在列中的一个数加它所在行的一个数之和,
不满足就是No,
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 int a[55][55]; 5 int main(){ 6 int n,i,j; 7 scanf("%d",&n); 8 for(i=1;i<=n;i++) 9 for(j=1;j<=n;j++) 10 cin>>a[i][j];//输入方格 11 12 for(i=1;i<=n;i++) 13 for(j=1;j<=n;j++) 14 if(a[i][j]!=1){ //大于1 15 bool flag =false ;//定义一个标志 16 for(int s=1;s<=n&&!flag;s++) //就样例一(3,1)举例 17 for(int t=1;t<=n&&!flag;t++) 18 flag=(a[i][j]==a[i][s]+a[t][j]); //(3,1)==(3,1)+(1,1),flag=false,t++,
//(3,1)==(3,1)+(2,1)……都不满足,返回上个循环,以此类推
19 if(!flag) { 20 printf("No\n");return 0; 21 } 22 } 23 printf("Yes\n"); 24 return 0; 25 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· 趁着过年的时候手搓了一个低代码框架
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· 乌龟冬眠箱湿度监控系统和AI辅助建议功能的实现