HDU 6076
来源:互联网 发布:音频切割软件 一刀切 编辑:程序博客网 时间:2024/06/16 16:26
Security Check
Problem Description
In airport of Bytetown, there are two long queues waiting for security check. Checking a person needs one minute, and two queues can be checked at the same time.
Picture from Wikimedia Commons
Two teams A and B are going to travel by plane. Each team has n players, ranked from 1 to n according to their average performance. No two players in the same team share the same rank. Team A is waiting in queue 1 while team B is waiting in queue 2. Nobody else is waiting for security check.
Little Q is the policeman who manages two queues. Every time he can check one person from one queue, or check one each person from both queues at the same time. He can't change the order of the queue, because that will make someone unhappy. Besides, if two players Ai and Bj are being checked at the same time, satisfying |Ai−Bj|≤k, they will make a lot of noise because their rank are almost the same. Little Q should never let that happen.
Please write a program to help Little Q find the best way costing the minimum time.
Picture from Wikimedia Commons
Two teams A and B are going to travel by plane. Each team has n players, ranked from 1 to n according to their average performance. No two players in the same team share the same rank. Team A is waiting in queue 1 while team B is waiting in queue 2. Nobody else is waiting for security check.
Little Q is the policeman who manages two queues. Every time he can check one person from one queue, or check one each person from both queues at the same time. He can't change the order of the queue, because that will make someone unhappy. Besides, if two players Ai and Bj are being checked at the same time, satisfying |Ai−Bj|≤k, they will make a lot of noise because their rank are almost the same. Little Q should never let that happen.
Please write a program to help Little Q find the best way costing the minimum time.
Input
The first line of the input contains an integer T(1≤T≤15), denoting the number of test cases.
In each test case, there are 2 integers n,k(1≤n≤60000,1≤k≤10) in the first line, denoting the number of players in a team and the parameter k.
In the next line, there are n distinct integers A1,A2,...,An(1≤Ai≤n), denoting the queue 1 from front to rear.
Then in the next line, there are n distinct integers B1,B2,...,Bn(1≤Bi≤n), denoting the queue 2 from front to rear.
In each test case, there are 2 integers n,k(1≤n≤60000,1≤k≤10) in the first line, denoting the number of players in a team and the parameter k.
In the next line, there are n distinct integers A1,A2,...,An(1≤Ai≤n), denoting the queue 1 from front to rear.
Then in the next line, there are n distinct integers B1,B2,...,Bn(1≤Bi≤n), denoting the queue 2 from front to rear.
Output
For each test case, print a single line containing an integer, denoting the minimum time to check all people.
Sample Input
14 22 3 1 41 2 4 3
Sample Output
7
Hint
Time 1 : Check A_1.Time 2 : Check A_2.
Time 3 : Check A_3.
Time 4 : Check A_4 and B_1.
Time 5 : Check B_2.
Time 6 : Check B_3.
Time 7 : Check B_4.
官方题解:
看题解看了好久,才明白,还是太菜了e_e.
当|ai-bj|<=k时直接转移,当|ai-bj|>k时,可以找到ai的左边第一个at,使得|at-b(j-i+t)|<=k,易知,
t<=k<=i-1这一段,有|ak-b(j-i+k)|>k;所以可以把这一段的转移压缩到只做一次,大大缩短的状态转移所需要的时间
阅读全文
0 0
- HDU 6076
- HDU 6076 题解
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- UVA 11752 The Super Powers
- 斜率优化dp
- HDU
- ZOJ
- HDU 6069
- HDU 6076
- 【C语言】对字母加密与解密(简易)
- hibernate数据库中文乱码问题解决
- 使用Scrapy爬取一个网站的数据
- 条款01:视C++为一个语言联邦
- cocos2d-js的自定义事件的两种创建方法
- 将Excel表导入MySQL
- 从键盘接收两个文件夹路径,把其中一个文件夹中的内容拷贝到另一个文件夹中
- Google算法题:轴对称