A8688 | Young Table
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
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_{xi}; 1<=q_{i}<=c_{pi})$ . The printed numbers denote swapping the contents of cells $a_{xi},y_{i}$ and $a_{pi},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.
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_{xi}; 1<=q_{i}<=c_{pi})$ . The printed numbers denote swapping the contents of cells $a_{xi},y_{i}$ and $a_{pi},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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted