A1075 | [COCI-2006_2007-contest3]#5 TENKICI
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko found a collection of N toy tanks dating back to the Second World War on his grandfather's attic. He promptly called his friend Slavko to play with him. They made a battlefield – a wooden board consisting of squares in N rows and N columns.
Each tank can be moved to one of the four neighbouring squares in a single move. A tank can shoot at any square in the same row and column. The tank is said to be guarding the row and column it is in.
Additionally, no two tanks can be in the same square at any time.
After many hours of play and two previous attempts, Mirko's mom yelled at them to come down for lunch again, and they decided to rearrange the tanks so that each tank guards a different row and column (meaning also that each row and column contains only one tank).
However, they want to do this using the minimum number of moves.
Write a program that finds the minimum number of moves required to rearrange the tanks so that each row and each column contains a single tank, and one such shortest sequence of moves.
Each tank can be moved to one of the four neighbouring squares in a single move. A tank can shoot at any square in the same row and column. The tank is said to be guarding the row and column it is in.
Additionally, no two tanks can be in the same square at any time.
After many hours of play and two previous attempts, Mirko's mom yelled at them to come down for lunch again, and they decided to rearrange the tanks so that each tank guards a different row and column (meaning also that each row and column contains only one tank).
However, they want to do this using the minimum number of moves.
Write a program that finds the minimum number of moves required to rearrange the tanks so that each row and each column contains a single tank, and one such shortest sequence of moves.
输入格式
The first line of input contains the integer N (5 ≤ N ≤ 500).
Each of the following N lines contains two integers R and C (1 ≤ R, S ≤ N), the row and column of a single tank at the moment of mom's call. No two tanks are on the same square.
Rows and columns are marked 1 through N, top-down and left-to-right.
Each of the following N lines contains two integers R and C (1 ≤ R, S ≤ N), the row and column of a single tank at the moment of mom's call. No two tanks are on the same square.
Rows and columns are marked 1 through N, top-down and left-to-right.
输出格式
Output the minimum number of moves (call this number K) on the first line.
Each of the next K lines should contain the tank being moved and the direction it is moved in,
separated by a single space.
Tanks are numbered 1 through N, in the order in which they are given in the input.
The direction can be one of four uppercase letters: 'L' for left, 'R' for right, 'U' for up and 'D' for down.
Note: The sequence need not be unique.
Each of the next K lines should contain the tank being moved and the direction it is moved in,
separated by a single space.
Tanks are numbered 1 through N, in the order in which they are given in the input.
The direction can be one of four uppercase letters: 'L' for left, 'R' for right, 'U' for up and 'D' for down.
Note: The sequence need not be unique.
输入输出样例
输入 #1
5 1 1 1 2 1 3 1 4 1 5
输出 #1
10 1 D 2 D 3 D 4 D 1 D 2 D 3 D 1 D 2 D 1 D
输入 #2
5 2 3 3 2 3 3 3 4 4 3
输出 #2
8 1 R 1 R 2 U 2 U 4 D 4 D 5 L 5 L
输入 #3
6 1 1 1 2 2 1 5 6 6 5 6 6
输出 #3
8 2 R 2 D 3 D 3 R 4 U 4 L 5 L 5 U
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