1 import java.io.BufferedReader; 2 import java.io.InputStreamReader; 3 import java.util.Arrays; 4 5 public class Main { 6 7 // 定义一个200的数组来表示过道,没经过一次都加一,然后排序,最大值*10就是结果 8 public static void main(String[] args) throws Exception { 9 BufferedReader reader = new BufferedReader(new InputStreamReader( 10 System.in)); 11 int numOfTestCase = Integer.parseInt(reader.readLine()); 12 for (int i = 0; i < numOfTestCase; i++) { 13 int[] times = new int[200]; 14 int numOfTables = Integer.parseInt(reader.readLine()); 15 for (int j = 0; j < numOfTables; j++) { 16 String line = reader.readLine(); 17 String[] nums = line.split(" "); 18 int t1 = Integer.parseInt(nums[0]); 19 int t2 = Integer.parseInt(nums[1]); 20 if(t1 > t2){ 21 int tmp = t2; 22 t2 = t1; 23 t1 = tmp; 24 } 25 int s1 = 0; 26 if (t1 % 2 != 0) { 27 s1 = t1 / 2; 28 } else { 29 s1 = t1 / 2 - 1; 30 } 31 int s2 = 0; 32 if (t2 % 2 != 0) { 33 s2 = t2 / 2; 34 } else { 35 s2 = t2 / 2 - 1; 36 } 37 for (int k = s1; k <= s2; k++) { 38 times[k]++; 39 } 40 } 41 Arrays.sort(times); 42 43 System.out.println(times[199] * 10); 44 } 45 } 46 }
需要注意:
1. 给出的数据中s不一定大于t
2. 定义一个数组表示走廊,每次被经过都++,最后sort,最大值*10