CF111E.Petya and Rectangle

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little Petya loves playing with rectangles. Mom bought Petya a rectangle divided into cells n × m in size (containing n rows, m columns). Petya marked two different cells of the rectangle and now he is solving the following task:

Let's define a simple path between those two cells as a sequence of distinct cells _a_1, _a_2, ..., a__k, where _a_1 and a__k are the two marked cells. Besides, a__i and a__i + 1 are side-neighboring cells of the path (1 ≤ i < k). Let's denote the path length as number k (the sequence length).

Petya's task is to find the longest simple path's length and to print the path. Help him.

小佩佳喜欢玩矩形。妈妈给佩佳买了一个被划分为 n×mn \times m 个格子的矩形(包含 nn 行、mm 列)。佩佳在该矩形中标记了两个不同的格子,现在他正在解决如下问题:

我们定义这两个标记格子之间的一条简单路径为一个由互不相同的格子构成的序列 a1,a2,…,aka_1, a_2, \dots, a_k,其中 a1a_1 和 aka_k 恰好是那两个被标记的格子;并且对任意 1≤i<k1 \le i < k,格子 aia_i 与 ai+1a_{i+1} 在网格中必须是边相邻(即共享一条边)的格子。我们将该路径的长度定义为整数 kk(即序列的长度)。

佩佳的任务是找出最长简单路径的长度,并输出该路径。请帮助他。

输入格式

The first line contains space-separated integers n and m (4 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the rectangle, correspondingly. The second line contains space-separated integers _x_1 and _y_1 — the coordinates of the first marked cell. The third line contains space-separated integers _x_2 _y_2 — the coordinates of the second marked cell (1 < _x_1, _x_2 < n, 1 < _y_1, _y_2 < m, _x_1 ≠ _x_2, _y_1 ≠ _y_2).

The coordinates of a marked cell are a pair of integers x y, where x represents the row's number and y represents the column's number. The rows are numbered from top to bottom with consecutive integers from 1 to n. The columns are numbered from the left to the right by consecutive integers from 1 to m.

It is guaranteed that the marked cells are not positioned in one row or column.

第一行包含两个用空格分隔的整数 nn 和 mm(4≤n,m≤10004 \leq n, m \leq 1000),分别表示矩形的行数和列数。
第二行包含两个用空格分隔的整数 x1x_1 和 y1y_1,表示第一个被标记的单元格的坐标。
第三行包含两个用空格分隔的整数 x2x_2 和 y2y_2,表示第二个被标记的单元格的坐标(满足 1<x1,x2<n1 < x_1, x_2 < n,1<y1,y2<m1 < y_1, y_2 < m,且 x1≠x2x_1 \ne x_2,y1≠y2y_1 \ne y_2)。

一个被标记单元格的坐标是一对整数 x yx\ y,其中 xx 表示行号,yy 表示列号。行号从上到下依次编号为 11 至 nn;列号从左到右依次编号为 11 至 mm。

保证这两个被标记的单元格既不在同一行,也不在同一列。

输出格式

In the first line print the length of the found path — k. In the next lines print k pairs of integers, one per line — coordinates of the cells that constitute the found path in the order, in which they follow in the path (the path must go from cell (_x_1, _y_1) to cell (_x_2, _y_2)). If there are several solutions, print any of them.

第一行输出找到的路径长度 kk。接下来的 kk 行中,每行输出一对整数——即构成该路径的各个格子的坐标(按路径中出现的顺序),路径必须从格子 (x1, y1)(x_1,\,y_1) 出发,到达格子 (x2, y2)(x_2,\,y_2)。若存在多种解,输出任意一种即可。

输入输出样例

  • 输入#1

    4 4
    2 2
    3 3

    输出#1

    15
    2 2
    1 2
    1 1
    2 1
    3 1
    4 1
    4 2
    4 3
    4 4
    3 4
    2 4
    1 4
    1 3
    2 3
    3 3

说明/提示

The statement test is described in the picture:

陈述测试如图所示:

输入解题思路,AI测评打分。不知道怎么写?

首页