/*
* Author: poj_whut_shz
* Problem: Moving Tables
* Code: poj_1083
* URL: http://poj.org/problem?id=1083
* Data: 2019/9/11
*/
/*
* 【题意分析】:
* 如图所示在一条走廊的两侧各有200个房间,
* 现在给定一些成对的房间相互交换桌子,但是搬运过程的路线不能交叉,
* 每次搬运消耗10min,问完成所有的搬运的最少用时。
*
* 【解题思路】:
* 利用房间号将走廊分割为一百份,每个“子走廊”都设置一个计数器,
* 搬运过程需要经过的子走廊计数器+1,
* 最后选出全部计数器的最大值,×10就是最终答案。
*/
package dp;
import java.util.Scanner;
public class P1083 {
private static int tests = 0; //需要处理的用例数量
private static int num = 0; //每个用例中需要搬运的桌子数量
private static int first = 0; //搬运桌子的起点
private static int second = 0; //搬运桌子的终点
private static int max = 0; //最终结果
private static int[] count; //子走廊计数器数组
//房间号转换为子走廊号
private static int toNum(int num) {
if(num % 2 == 0) {
return ((num / 2) - 1);
}
else {
return ((num - 1) / 2);
}
}
//操作计数器
private static void addCount(int first, int second) {
if(first > second) { //保证起点小于等于终点
int temp = first;
first = second;
second = temp;
}
for(; first <= second; first++) {
count[first]++;
}
}
//获得最大值
private static void findMax() {
for(int i = 0; i < 100; i++) {
if(count[i] > max) {
max = count[i];
}
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
tests = scan.nextInt();
for(int i = 0; i < tests; i++) { //对每个用例循环操作
num = scan.nextInt();
count = new int[100];
for(int j = 0; j < num; j++) {
first = toNum(scan.nextInt());
second = toNum(scan.nextInt());
addCount(first, second); //操作计数器
}
findMax(); //找到最大值
System.out.println(max * 10); //打印结果
}
scan.close();
}
}