CF858E.Tests Renumeration
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests.
Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only.
The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command.
Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run:
- all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples;
- all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests.
全贝尔兰信息学奥林匹克竞赛刚刚结束!现在,弗拉基米尔希望将本次奥赛的题目作为 Gym 题目上传至广受欢迎的 Codehorses 网站。
不幸的是,奥赛数据存档十分混乱。例如,测试用例文件的命名是任意的,毫无规律可言。
弗拉基米尔希望重命名这些测试文件,使其新文件名是互不相同、从 1 开始连续递增的整数,即 "1", "2", ..., "_n_",其中 _n_ 是测试用例的总数。
部分文件包含题面中的示例测试(examples),其余文件则包含常规测试(regular tests)。有可能不存在任何示例测试,也有可能所有测试均为示例测试。弗拉基米尔希望重命名后,示例测试占据编号最靠前的若干个位置(即文件名 "1", "2", ..., "_e_"),而其余所有后续文件均仅包含常规测试(即文件名 "_e_ + 1", "_e_ + 2", ..., "_n_")。
弗拉基米尔唯一能执行的操作是 move 命令。他需要编写一个脚本文件,其每一行形如 "move file\_1 file\_2",表示将文件 "file\_1" 重命名为 "file\_2"。当执行该命令时,若当前已存在名为 "file\_2" 的文件,则该文件将被覆盖(即其内容被 "file\_1" 的内容取代)。执行完 "move file\_1 file\_2" 后,文件 "file\_1" 不再存在,而文件 "file\_2" 存在,且其内容与执行 move 命令前 "file\_1" 的内容完全相同。
请帮助弗拉基米尔编写一个脚本文件,使得其行数尽可能少,并保证执行该脚本后满足以下条件:
- 所有示例测试位于最前面的若干个测试中,其文件名依次为
"1","2", ...,"_e_",其中_e_是示例测试的总数; - 其余所有文件均为常规测试,其文件名依次为
"_e_ + 1","_e_ + 2", ...,"_n_",其中_n_是所有测试的总数。
输入格式
The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests.
n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.
第一行包含一个整数 n(1≤n≤105)—— 表示测试文件的数量。
接下来有 n 行,每行描述一个测试文件。每行的格式为 name_i type_i,其中 name_i 是文件名,type_i 为 "1" 表示第 i 个文件包含一个样例测试,为 "0" 表示包含一个常规测试。每个文件名均由数字和小写英文字母组成,长度为 1 至 6 个字符。所有文件名均保证互不相同。
输出格式
In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.
第一行输出弗拉基米尔脚本文件所需的最少行数。
随后输出该脚本文件,每一行应为 "move file\_1 file\_2",其中 "file\_1" 是执行该行命令时已存在的文件名,而 "file\_2" 是一个由数字和小写英文字母组成的字符串,长度为 1 至 6。
输入输出样例
输入#1
5 01 0 2 1 2extra 0 3 1 99 0
输出#1
4 move 3 1 move 01 5 move 2extra 4 move 99 3
输入#2
2 1 0 2 1
输出#2
3 move 1 3 move 2 1 move 3 2
输入#3
5 1 0 11 1 111 0 1111 1 11111 0
输出#3
5 move 1 5 move 11 1 move 1111 2 move 111 4 move 11111 3
输入解题思路,AI测评打分。不知道怎么写?