求助!0分 WA+TLE
查看原帖
求助!0分 WA+TLE
931839
chenweijie楼主2023/3/11 13:31


import java.util.Scanner;

public class acwing {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] t = new int[n];//开始时间
        int[] s = new int[n];//结束时间
        for (int i = 0; i < n; i++) {
            t[i] = in.nextInt();
            s[i] = in.nextInt();
        }
        //按结束时间排序
        for (int i = 0; i < n - 1; i++)
            for (int j = i + 1; j < n; j++) {
                if (t[i] > t[j]) {
                    int k = t[i];
                    t[i] = t[j];
                    t[j] = k;
                    int m = s[i];
                    s[i] = s[j];
                    s[j] = m;
                }
            }
        int count = 0;
        int ans = 0;
        for (int i = 1; i < n; i++) {
            if(s[i] >= t[ans]){
                count++;
                ans = i;
            }
        }
        System.out.println(count);
    }


}
2023/3/11 13:31
加载中...