度小满笔试题

算法1

算法2

image-20220916164327108

代码为:

差分方法

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
import java.util.*;

public class Main2 {
static int N = 100010;
static int arr[] = new int[N];
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int s = 0;
int n = scanner.nextInt();
int h = scanner.nextInt();
int max = 0;
int l,r;
for (int i = 0;i<n;i++){
l = scanner.nextInt();
r = scanner.nextInt();
arr[l]++;
arr[r++]--;
max = Math.max(max,r);
}
int res = 0;
for (int i = 1;i<=max;i++){
arr[i] = arr[i]+arr[i-1];
if (arr[i]>=h) res++;
}
System.out.println(res);
}
}

算法3

image-20220916165235709


度小满笔试题
http://example.com/2022/09/16/度小满笔试题/
作者
zlw
发布于
2022年9月16日
许可协议