Matrix Walk CodeForces

  题意:

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

  

  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 = 1;
    cin>> n;
    for(int i=0; i<n; i++)
    {
        cin>> a[i];
        if(i == 0)
            continue;
        if(a[i] == a[i-1])
        {
            cout<< "NO" <<endl;
            return 0;
        }
        if(abs(a[i] - a[i-1]) != 1)
            y = abs(a[i] - a[i-1]);
    }
    for(int i=1; i<n; i++)
    {
        if(abs(a[i] - a[i-1]) != 1 && abs(a[i] - a[i-1]) != y)
        {
            cout<< "NO" <<endl;
            return 0;
        }
        if(a[i] % y == 0 && a[i - 1] - a[i] == 1 && y != 1) {
            cout<<"NO"<<endl;return 0;
        } else if(a[i] % y == 1 && a[i] - a[i - 1] == 1 && y != 1) {
            cout<<"NO"<<endl;return 0;
        }
    }
    cout<<"YES"<<endl<<1000000000<<' '<<y<<endl;


    return 0;
}
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
原文地址:https://www.cnblogs.com/WTSRUVF/p/9406651.html