A8499 | Defragmentation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The first line contains two integers $n$ and $m$ ( $1<=n,m<=200$ ) — the number of clusters and the number of files, correspondingly. Next $m$ lines contain descriptions of the files. The first number in the line is $n_{i}$ ( $n_{i}>=1$ ), the number of clusters occupied by the $i$ -th file. Then follow $n_{i}$ numbers $a_{i,1}$ , $a_{i,2}$ , ..., $a_{i,ni}$ ( $1<=a_{i,j}<=n$ ). It is guaranteed that each cluster number occurs not more than once and , that is, there exists at least one unused cluster. Numbers on each line are separated by spaces.
输入格式
In the first line print a single integer $k$ ( $0<=k<=2n$ ) — the number of operations needed to defragment the disk. Next $k$ lines should contain the operations' descriptions as " $i$ $j$ " (copy the contents of the cluster number $i$ to the cluster number $j$ ).
输出格式
Let's say that a disk consists of $8$ clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation.
Example 2: each file must occupy a contiguous area of memory.
Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one.
Example 4: violating the order of file fragments to each other is not allowed.
Example 5: unused clusters should be located at the end, and in this example the unused clusters are $3$ , $7$ , $8$ .
Example 2: each file must occupy a contiguous area of memory.
Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one.
Example 4: violating the order of file fragments to each other is not allowed.
Example 5: unused clusters should be located at the end, and in this example the unused clusters are $3$ , $7$ , $8$ .
输入输出样例
输入 #1
7 2 2 1 2 3 3 4 5
输出 #1
0
输入 #2
7 2 2 1 3 3 2 4 5
输出 #2
3 2 6 3 2 6 3
Let's say that a disk consists of $8$ clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation.
Example 2: each file must occupy a contiguous area of memory.
Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one.
Example 4: violating the order of file fragments to each other is not allowed.
Example 5: unused clusters should be located at the end, and in this example the unused clusters are $3$ , $7$ , $8$ .
Example 2: each file must occupy a contiguous area of memory.
Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one.
Example 4: violating the order of file fragments to each other is not allowed.
Example 5: unused clusters should be located at the end, and in this example the unused clusters are $3$ , $7$ , $8$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted