欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java实现 洛谷 P1047 校门外的树

程序员文章站 2022-07-13 11:19:14
...

Java实现 洛谷 P1047 校门外的树

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean[] b = new boolean[sc.nextInt() + 1];
        int t = sc.nextInt(), ans = 0;

        while(t-- > 0) {
            int start = sc.nextInt(), end = sc.nextInt();
            for(int i = start; i <= end; ++i)
                b[i] = true;
        }
        for(int i = 0; i < b.length; ++i)
            if(!b[i]) ans++;
        System.out.println(ans);
        sc.close();
    }
}