 数组
数组
  # 华为
# 机器人监考
题目描述:
同时监考一场消耗3个金币,监考多场消耗4个金币,不监考消耗1个金币,计算机器人花费;
输入:
第一行考试次数 n;
接下来n行分别为:起始时间,结束时间;
输出:
花费金币数;
案例:
3 1 5 4 6 6 6 输出 :211
2
3
4
5
public class T3 {
    static int[] time = new int[100006];
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.valueOf(br.readLine());
        int min = Integer.MIN_VALUE;
        int max = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            String[] input = br.readLine().split(" ");
            int l = Integer.valueOf(input[0]);
            int r = Integer.valueOf(input[1]);
            min = Math.min(min,l);
            max = Math.max(max,r);
            time[l]++;
            time[r+1]--;
        }
        int ans = 0;
        int pre = 0;
        for(int i=min;i<=max;i++){
            int cur = pre+time[i];
            pre = cur;
            if(cur==0){
                ans += 1;
            }else if(cur==1){
                ans += 3;
            }else {
                ans += 4;
            }
        }
        System.out.println(ans);
    }
}
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
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
