CF 954C Matrix Walk

【信息科学与工程学】计算机科学与技术——第七十七篇 系统架构设计02 编号类型模型配方企业资本运作的方法/规则/条件/依据及所有的步骤(​风险处理/异常处理/危机应对关联知识法律法规和裁决依据​​由发起人(通常是知名投资人、投行或产业资本)先设立一个只有现金、无实际业务的特殊目的收购公司(SPAC),通过IPO募集资金并在交易所上市。然后在规定时间内(通常24个月)寻找一家非上市公司进行合并(De-SPAC),使目标公司迅速实现上市,规避传统IPO的复杂流程和不确定性。1.:在开曼或特拉华注册空壳公司,注入少量种子资金。2. 阅读详情

题目

There is a matrix A of size x × y filled with integers. For every , Ai, j = y(i − 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.

You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1,a2,...,an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.

From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:

  1. (i + 1, j) — only if i < x;
  2. (i, j + 1) — only if j < y;
  3. (i − 1, j) — only if i > 1;
  4. (i, j − 1) — only if j > 1.

Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don’t know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don’t contradict with your sequence of moves?

Input
The first line contains one integer number n (1 ≤ n ≤ 200000) — the number of cells you visited on your path (if some cell is visited twice, then it’s listed twice).

The second line contains n integers a1,a2,...,an (1 ≤ ai ≤ 109) — the integers in the cells on your path.

Output
If all possible values of x and y such that 1 ≤ x, y ≤ 109 contradict with the information about your path, print NO.

Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.

Examples

Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3

Input
6
1 2 1 2 5 3
Output
NO

Input
2
1 10
Output
YES
4 9

Note
The matrix and the path on it in the first test looks like this:


Also there exist multiple correct answers for both the first and the third examples.

分析

【题意】
给一个只含1~n的路径,选择长宽按照1~n顺序排列的方式生成一个地图,使得路径合法。

【分析】

  • 对于一个图而言,宽度w定了以后,所有的点的位置就确定了,而长度只影响取值的范围。所以我们不关心长度,只关心宽度w。
  • 在一个宽度为w的图上移动,上下走的跨度也是w,而左右走的跨度永远是1,所以对于合法的路径而言,相邻的两个点的差不是1,就是w。所以我们只关心它的跨度w。

判断某条路径合法,首先应该满足上面第二条基本性质,才有可能找到一个地图吧——一旦某两个点的差是一个大于1的数,说明它向上/下走了,也就间接限制了地图的宽度只能是这么多,那么反过来,地图的宽度也限制了向上/下走的跨度只能是这么多。所以一个合法路径只能有一个跨度。

在路径的跨度也就是地图的w确定以后,再检查是否合法就容易多了,只需根据每个位置计算出向上下左右行走的可能,并判度下一个位置是否是可能性中的一种就行了。

【注意】
如果两个点是上下关系,它们相差w就一定相邻,反之就一定不相邻,相差w是一个很强的条件。
如果两个点是左右关系,它们相差1并不能决定是否相邻,需要对它们的行列关系进行具体判断。

与其对两个点做很多的判断,我觉得不如把从一个点出发会到达的四种可能算出来,然后看其中有没有路径上的下一个点。

代码

#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mabs(x) ((x)>0?(x):(0-(x)))

#define N_max    200005
int arr[N_max];

int w=1;
int next[4];//0~3代表向上下左右行走会到哪里,-1表示不能走
void cal(int v, int w) {
    int x = v / w;
    int y = v%w;
    //上下好计算
    next[0] = ((v - w) > 0 ? v - w : -1);//考虑上边界
    next[1] = (v + w);
    next[2] = ((v - 1)>0 ? v - 1 : -1);//考虑左边界
    next[3] = v + 1;
    //左右需特判
    if (y== 0)
        next[3] = -1;
    else if (y == 1)
        next[2] = -1;
}
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) 
        scanf("%d", &arr[i]);
    for (int i = 1; i < n; ++i)
    {
        if (mabs(arr[i] - arr[i - 1]) > w) {
            if (w > 1) {
                printf("NO"); return 0;
            }
            w = mabs(arr[i] - arr[i - 1]);
        }   
    }
    int flag = 0;
    for (int i = 1; i < n; ++i) {
        flag = 0;
        cal(arr[i-1],w);
        for (int t = 0; t < 4; ++t)if (next[t] == arr[i])flag = 1;
        if (flag == 0) {
            printf("NO");
            return 0;
        }
    }
    printf("YES\n1000000000 %d",w);
}

总结

当直接判断两个点的关系是否正确很繁琐时,不妨考虑从一个点生成所有可能转移到的点,再检查这个集合是不是含有另一个点。

Linux内存压力测试工具【memtester】详且精 对Linux下的压力测试工具memtester有一个比较人性化的概述,以及避坑心得。 阅读详情

相关推荐

避坑指南:ShardingSphere连接达梦/金仓数据库时SQL解析器的那些‘坑‘

本文深入探讨了ShardingSphere与国产数据库(如达梦、金仓)集成时遇到的SQL解析器差异问题,提供了详细的解决方案和优化策略。通过分析SQL方言差异、JDBC实现差异及解析器兼容性,帮助开发者有效避坑,提升分布式数据库架构设计的效率与稳定性。

weixin_29309475的博客 392

954C. Matrix Walk

There is a matrix A of size x × y filled with integers. For every , Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in this...

码农的一亩三分地 287

读书笔记 | 财务会计理论(第7版 William R.Scott)(中):契约视角下的会计信息价值

本文从契约理论视角深入剖析了财务会计信息的核心价值。文章指出,会计信息作为关键的“契约润滑剂”,通过债务合同与薪酬合同等具体形式,有效解决了公司内外的信息不对称与道德风险问题,协调了股东、债权人及管理层等多方利益,是公司治理与资本市场有效运转的基石。

mac99的博客 330

CodeForces 954C Matrix Walk

题目链接:CF 954C这道比赛时候卡了好多的人啊。。看榜的时候发现大家都是wa了89发。。。贼坑其实想的简单一点,先找到y值,再检查一遍就好了~因为每个点只能向四个方向走,我们把这四个点的值与起始点的值相减,会发现只能是±1和±y,那么取绝对值之后除了1只能有1个值(y),有两个值就肯定错了第二遍检查的时候,要注意两种情况(0的情况在第一步就可以判断)①在右边界向右走②在左边界向左走处理之后找最...

大乐的博客 537

【数字图像处理第四版课后习题答案】第2章 数字图像基础(含英文原版)

如图 P2.3 所示,视网膜图像中与点相对应的直径 x 是由类似的三角形得到的。即得出 x = 0.085d。根据第 2.1 节中的讨论,并结合一些自由解释,我们可以将眼窝视为一个方形传感器阵列,拥有大约 337,000 个元素,这相当于一个大约 580×580 个元素的阵列。假设元素间距相等,则在 1.5 毫米长的直线上有 580 个元素和 579 个空间,共计 1,159 个。换句话说,如果一个点的直径 d<1.3×10-6 m,或者 d<15.3×10 m,眼睛就无法检测到这个点。

weixin_56463218的博客 1万+

【SigmaStar SSC335系列】空片用Flash_Tool烧写

简介 本文主要讲新拿到的PCBA,板上spi nand flash还是空的,如何在这种情况下烧录固件,这里讲解用官方Flash_Tool烧写的方式。 但只讲一些注意的地方和坑,其它的官方文档里说的比较清楚,不多说。 准备 Flash_Tool烧写软件 编译打包好烧写镜像 串口烧录小板 ----- 这个是个坑,在官方文档里并没有提及,刚开始用的平时调试的USB转串口,怎么都没反应,一度不知烧写软件不对还是硬件有问题,最后通过厂家技术支持才得知,除了专门的Flash_Tool外,还要专门的串口烧录器

老K 4697

codeforces954 C. Matrix Walk【思维】

C. Matrix Walk time limit per test1 second memory limit per test256 megabytes There is a matrix A of size x × y filled with integers. For every , Ai, j = y(i - 1) + j. Obviously, every integer fro...

nobleman 1772

Mixly米思齐——超声波测距控制LED灯

为了更加地贴近中小学信息技术的课程,我们用米思齐做了一个实验——根据距离的远近开启警报灯(利用超声波测出距离)。 实验硬件准备 arduino uno R3 、USB 数据线、YFROBOT UNO I/O扩展板、YFROBOT超声波传感器模块、模块3P连接线x1、LED灯x1 硬件连接图如下: 在arduino uno R3 上再接一个LED灯,实物图如下: 在本次实验中,LE...

Janise_的博客 9977

Educational Codeforces Round 40 (Rated for Div. 2)

A. Diagonal Walkingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMikhail walks on a 2D plane. He can go either up or right. You are given a seque...

J. Cole 693

【Simulink教程案例18】基于simulink的基础OFDM+64QAM发射接收链路仿真

OFDM(Orthogonal Frequency Division Multiplexing)即正交频分复用技术,实际上OFDM是MCM(Multi Carrier Modulation),多载波调制的一种。通过频分复用实现高速串行数据的并行传输, 它具有较好的抗多径衰落的能力,能够支持多用户接入。OFDM技术由MCM(Multi-Carrier Modulation,多载波调制)发展而来。OFDM技术是多载波传输方案的实现方式之一,它的。

FPGA/MATLAB学习教程/源码/项目合作开发 1984

K-Core, K-Shell & K-Crust傻傻分不清楚

K-Core(K-核)就是所有大于等于K的K-Shell的并集;K-Crust(K-皮)就是所有小于等于K的K-shell的并集。

欢迎订阅 -- 小源笔迹 2255

D. Walk on Matrix(超详细讲了原理)

D. Walk on Matrix 标签 构造 简明题意 假设有一个数字矩阵,每次可以向下或向右,问从左上角走到右下角的数字和最多是多少,那么显然这是一个dp。 现在不问你数字和,而是把路径上的所有数都&起来,如果还是dp显然是错的。假设dp的到的结果是x,正确答案是y。 现在给定k,需要你构造一个矩阵,使得|y-x|=k 思路 首先我们思考什么时候dp是错的。假设矩阵中...

danzh 1101

prometheus普罗米修斯集监控外部k8s

prometheus普罗米修斯集监控外部k8s

你是我一生的追求 2247

Matrix Walk CodeForces - 954C(模拟 很多要注意的细节)

题目思路 看完题意其实就能知道是个模拟题 可是需要注意的细节非常多 wa了一年 对着cf的数据一直改 还是wa 后来看了下别人的写法 发现我每次写模拟都喜欢只考虑当前的值 但是很多时候直接从全局考虑会简单很多 要注意行的长度为1的情况 考虑只有一个数的时候 然后行的个数直接输出1000000000就好了 列的个数要进行分类讨论 ac代码 #include <stdio.h> #include <iostream> #include <algorithm> #include

daydreamer23333的博客 282

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

CF1332D Walk on Matrix

原题链接 90个测试点好评 简要题意: 求一个矩阵走过的最大 &\&& 和(只能往右、下走),然后有这样一个程序: initialize dpi,j←0,for all 0≤i≤n,0≤j≤m,except dp0,1←a1,1\texttt{initialize} \space dp_{i,j} \gets 0 , \texttt{...

bifanwen的博客 373

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk (一定要细心啊)

C. Matrix Walktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a matrix A of size x × y filled with integers. For every , Ai, j = y(i - 1) ...

feifancaicai的博客 404

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

B. Sereja and Mirroring

解题说明:此题可以等价看成一道图形题,

无知的我 1601

Codeforces 954 C. Matrix Walk

好久没更新了 最近做的一些题,陆续写上来一些吧 ,,,C. Matrix Walktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a matrix A of size x × y filled with integers. Fo...

Amo丶 274

Codeforces 365C 思维或二分

C. Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b ...

qq_36876305的博客 282

Codeforces Round 40 (Rated for Div. 2) C - Matrix Walk

There is a matrix A of size x × y filled with integers. For every 1&lt;=i&lt;=x,1&lt;=j&lt;=y,Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.You have tr...

深海沧澜的博客 375

Codeforces Sereja and Mirroring

Description Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following

小张的专栏 804

Codeforces Educational 38 C. Constructing Tests ( 构造

题目描述 Let’s denote a m-free matrix as a binary (that is, consisting of only 1’s and 0’s) matrix such that every square submatrix of size m × m of this matrix contains at least one zero. Consider the ...

Yishui_lovely 599

D - Matrix Walk

There is a matrix A of size x × y filled with integers. For every , Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in thi...

qq_42865713的博客 310

Codeforces Round #243 (Div. 2)

又要掉分了。。。

龙崎的专栏 655

AtCoder Beginner Contest 085 D Katana Thrower(贪心)

Problem Statement You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kind

toby的博客 928

codeforces 922 C Cave Painting

能同时满足n mod i = i -1 (i = 1, 2, 3, ..., k)的n有多少个呢?

toby的博客 898
上一篇: codeforces 967 D Resource Distribution
下一篇: 牛客练习赛17 C 操作数(矩阵快速幂)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值