A1072 | [COCI-2006_2007-contest3]#2 LISTA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko received a birthday present from his aunt in the US – a brand-new doubly-linked list (an example of which is shown in the figure below). The list contains N nodes numbered 1 through N. Two types of moves can be done on the list:
A) Move node X in front of node Y.
B) Move node X after node Y.
Mirko played with his new toy for hours, writing down each move on a piece of paper so that he can reconstruct the list's initial state (nodes 1 through N in order from left to right).
When he decided to reconstruct the list, Mirko was astonished to find that there is no easy way to invert the moves and restore the list's initial state. Mirko cannot know where node X was prior to each move, only where it ended up.
Seeing how Mirko is still recovering from the shock, write a program that finds a minimal sequence of moves that restored the list's initial state from Mirko's logs.
A) Move node X in front of node Y.
B) Move node X after node Y.
Mirko played with his new toy for hours, writing down each move on a piece of paper so that he can reconstruct the list's initial state (nodes 1 through N in order from left to right).
When he decided to reconstruct the list, Mirko was astonished to find that there is no easy way to invert the moves and restore the list's initial state. Mirko cannot know where node X was prior to each move, only where it ended up.
Seeing how Mirko is still recovering from the shock, write a program that finds a minimal sequence of moves that restored the list's initial state from Mirko's logs.
输入格式
The first line of input contains two integers N and K (2 ≤ N ≤ 500 000, 0 ≤ M ≤ 100 000), the number of nodes and the number of moves made by Mirko.
Each of the next M rows contains a description of a single move made by Mirko – the type of move ('A' or 'B') and two integers X and Y.
Each of the next M rows contains a description of a single move made by Mirko – the type of move ('A' or 'B') and two integers X and Y.
输出格式
Output the minimum number of moves (call this number K) on the first line.
Each of the next K lines should contain a description of a single move in the same format as in the input.
Note: The sequence need not be unique.
Each of the next K lines should contain a description of a single move in the same format as in the input.
Note: The sequence need not be unique.
输入输出样例
输入 #1
2 1 A 2 1
输出 #1
1 A 1 2
输入 #2
4 3 B 1 2 A 4 3 B 1 4
输出 #2
2 A 1 2 B 4 3
输入 #3
6 5 A 1 4 B 2 5 B 4 2 B 6 3 A 3 5
输出 #3
3 A 4 5 B 6 5 A 2 3
If both the number K and the sequence of moves are correct, your program will score full points on
the test case.
If your program outputs the correct number K and does not output the sequence of moves, or the
sequence of moves is incorrect, you will get 60% of the points for that test case.
the test case.
If your program outputs the correct number K and does not output the sequence of moves, or the
sequence of moves is incorrect, you will get 60% of the points for that test case.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted