杭电1050

http://acm.hdu.edu.cn/showproblem.php?pid=1050

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package oj;

import java.util.Scanner;

public class Main_1050 {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
long n = scanner.nextInt();
int[] a = new int[200];
for (int i = 0; i < n; i++) {
int s = scanner.nextInt();
int e = scanner.nextInt();
s=(s-1)/2;
e=(e-1)/2;
if (e<s) {
int temp=e;
e=s;
s=temp;
}
for (int j = s; j <=e; j++) {
a[j] += 1;
}
}
int min = a[0];
for (int i = 0; i < a.length; i++) {
if (a[i] > min) {
min = a[i];
}
}
System.out.println(min*10);

}
}
}

有400个房间,但是走廊长度是200.所以才有

1
2
s=(s-1)/2;
e=(e-1)/2;

只要找出某个走廊段,需要被使用的次数最多,就是最少使用时间。
贪心算法入门