博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder-3920
阅读量:4351 次
发布时间:2019-06-07

本文共 1679 字,大约阅读时间需要 5 分钟。

We have a 3×3 grid. A number ci,j is written in the square (i,j), where (i,j) denotes the square at the i-th row from the top and the j-th column from the left.

According to Takahashi, there are six integers a1,a2,a3,b1,b2,b3 whose values are fixed, and the number written in the square (i,j) is equal to ai+bj.
Determine if he is correct.

Constraints

  • ci,j (1≤i≤3,1≤j≤3) is an integer between 0 and 100 (inclusive).
Input

Input is given from Standard Input in the following format:

c1,1 c1,2 c1,3c2,1 c2,2 c2,3c3,1 c3,2 c3,3
Output

If Takahashi's statement is correct, print Yes; otherwise, print No.

Sample Input 1

1 0 12 1 21 0 1
Sample Output 1

Yes

Takahashi is correct, since there are possible sets of integers such as:a1=0,a2=1,a3=0,b1=1,b2=0,b3=1.

Sample Input 2

2 2 22 1 22 2 2
Sample Output 2

No

Takahashi is incorrect in this case.

Sample Input 3

0 8 80 8 80 8 8
Sample Output 3

Yes
Sample Input 4

1 8 62 9 70 7 7
Sample Output 4

No

题解:这一题由于给的数据范围不大,所以可根据关系式,遍历每个整数A;看是否找到使关系式成立的A。如有,则输出Yes,否则输出No

AC代码为:

#include<cstdio>

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[4][4];
int main()
{
for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
cin >> a[i][j];
}
}
int flag = 1;
for (int k = -1000; k <= 1000; k++)
{
int a2, a3, b1, b2, b3;
int a1 = k;
b1 = a[1][1] - k;
b2 = a[1][2] - k;
b3 = a[1][3] - k;
a2 = a[2][1] - b1;
a3 = a[3][1] - b1;
if (a[2][2] != a2 + b2) flag = 0;
if (a[2][3] != a2 + b3) flag = 0;
if (a[3][2] != a3 + b2) flag = 0;
if (a[3][3] != a3 + b3) flag = 0;
if (flag)
{
break;
}
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}

转载于:https://www.cnblogs.com/songorz/p/9386609.html

你可能感兴趣的文章
Upgrade Bash to 4+ on OS X
查看>>
python学习笔记(六)time、datetime、hashlib模块
查看>>
uva489(需要考虑周全)
查看>>
C-关键字(二)
查看>>
排序笔记
查看>>
天气API整理,返回的数据格式为json对象
查看>>
如何配置JAVA的环境变量、Tomcat环境变量
查看>>
MySQL定义外键的方法
查看>>
ELK Packetbeat 部署指南(15th)
查看>>
ant 打不同渠道包
查看>>
andorid 字体 修改
查看>>
oracle日期函数、字符串函数、格式化方式
查看>>
咏南APP(手机)开发框架
查看>>
第三周学习进度总结
查看>>
05:年龄与疾病
查看>>
POJ 1873
查看>>
POJ_1679_The Unique MST(次小生成树模板)
查看>>
JSP
查看>>
每天一个JavaScript实例-展示设置和获取CSS样式设置
查看>>
一篇文章教你如何用R进行数据挖掘
查看>>