CF237B.Young Table

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains c__i cells, at that for all i (1 < i ≤ n) holds c__i ≤ c__i - 1.

Let's denote s as the total number of cells of table a, that is, . We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct.

Let's assume that the cells of the i-th row of table a are numbered from 1 to c__i, then let's denote the number written in the j-th cell of the i-th row as a__i, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions:

  1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ c__i) holds a__i, j > a__i - 1, j;
  2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ c__i) holds a__i, j > a__i, j - 1.

In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap.

Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations.

你有一个表格 a,包含 n 行,行号从 1 到 n。表格 a 的第 i 行包含 c__i 个单元格,且对所有 i(1 < i ≤ n)均满足 c__i ≤ c__i − 1。

记 s 为表格 a 的单元格总数,即 。已知表格中每个单元格都填有一个 1 到 s 之间的整数,且所有填入的整数互不相同。

设表格 a 的第 i 行的单元格编号为 1 到 c__i,并记第 i 行第 j 个单元格中的数为 a__i, j。你的任务是执行若干次交换操作,重新排列表格中的数字,使其满足以下两个条件:

  1. 对所有 i, j(1 < i ≤ n;1 ≤ j ≤ c__i),均有 a__i, j > a__i − 1, j;
  2. 对所有 i, j(1 ≤ i ≤ n;1 < j ≤ c__i),均有 a__i, j > a__i, j − 1。

在一次交换操作中,你可以任选表格中两个不同的单元格,并交换其中的数字:即交换前位于第一个被选单元格中的数字,将在交换后写入第二个被选单元格;同理,交换前位于第二个被选单元格中的数字,将在交换后写入第一个被选单元格。

请将数字按上述要求重新排列。注意:你允许执行任意次数的操作,但最多执行 s 次。你无需最小化操作次数。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers c__i (1 ≤ c__i ≤ 50; c__i ≤ c__i - 1) — the numbers of cells on the corresponding rows.

Next n lines contain table а. The i-th of them contains c__i space-separated integers: the j-th integer in this line represents a__i, j.

It is guaranteed that all the given numbers a__i, j are positive and do not exceed s. It is guaranteed that all a__i, j are distinct.

第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50),表示表格的行数。
第二行包含 nn 个用空格分隔的整数 cic_i(1≤ci≤501 \leq c_i \leq 50;ci≤ci−1c_i \leq c_{i-1}),表示对应各行的单元格数量。

接下来的 nn 行描述表格 aa。其中第 ii 行包含 cic_i 个用空格分隔的整数:该行中第 jj 个整数表示 ai,ja_{i,j}。

保证所有给定的数 ai,ja_{i,j} 均为正数且不超过 ss;同时保证所有 ai,ja_{i,j} 互不相同。

输出格式

In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps.

In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers x__i, y__i, p__i, q__i (1 ≤ x__i, p__i ≤ n; 1 ≤ y__i ≤ c__x__i; 1 ≤ q__i ≤ c__p__i). The printed numbers denote swapping the contents of cells a__x__i, y__i and a__p__i, q__i. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed.

第一行输出一个整数 mm(0≤m≤s0 \leq m \leq s),表示执行的交换操作次数。

接下来 mm 行,每行描述一次交换操作。第 ii 行输出四个用空格分隔的整数 xi, yi, pi, qix_i,\ y_i,\ p_i,\ q_i(其中 1≤xi, pi≤n1 \leq x_i,\ p_i \leq n;1≤yi≤cxi1 \leq y_i \leq c_{x_i};1≤qi≤cpi1 \leq q_i \leq c_{p_i})。这些数字表示交换单元格 axi,yia_{x_i,y_i} 与 api,qia_{p_i,q_i} 中的内容。注意,一次交换操作会改变两个不同表格单元格的内容。请按实际执行顺序输出这些交换操作。

输入输出样例

  • 输入#1

    3
    3 2 1
    4 3 5
    6 1
    2

    输出#1

    2
    1 1 2 2
    2 1 3 1
  • 输入#2

    1
    4
    4 3 2 1

    输出#2

    2
    1 1 1 4
    1 2 1 3

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

首页