Matrix Walk CodeForces - 954C

时间:2023-03-10 07:18:17
Matrix Walk CodeForces - 954C

  题意:

  就是给出一连串的数字 这些数字是从第一个数字依次走过的

  Matrix Walk CodeForces - 954C

  emm。。就是这样。。  然后让你判断这个矩阵是否存在  如果存在输出行和列的数量  其中行。。开到最大就好了。。。主要是判断列

  在输入的这些数中  如果出现一个数字和上一个不是连续的数字  则就能判断列了 y = abs(a[i] - a[i-1])  然后如果再有不连续的 判断一下是否符合

  abs(a[i] - a[i-1])= y  如果不符合 则NO  当然还有两个坑,,,1、可能a[i] == a[i-1]这样也是NO  因为题中说是走到四个方向

  2、在知道y以后 如果a[i]和a[i-1]连续 但a[i]%y == 0 这样也是NO 例如上图中的3 和 4 是不能一步从3 到 4 的   当然4也不能到3

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int a[maxn];
int main()
{
int n, y = ;
cin>> n;
for(int i=; i<n; i++)
{
cin>> a[i];
if(i == )
continue;
if(a[i] == a[i-])
{
cout<< "NO" <<endl;
return ;
}
if(abs(a[i] - a[i-]) != )
y = abs(a[i] - a[i-]);
}
for(int i=; i<n; i++)
{
if(abs(a[i] - a[i-]) != && abs(a[i] - a[i-]) != y)
{
cout<< "NO" <<endl;
return ;
}
if(a[i] % y == && a[i - ] - a[i] == && y != ) {
cout<<"NO"<<endl;return ;
} else if(a[i] % y == && a[i] - a[i - ] == && y != ) {
cout<<"NO"<<endl;return ;
}
}
cout<<"YES"<<endl<<<<' '<<y<<endl; return ;
}