10-12 华为笔试第二题95%求指正
第一题AC 第三题放弃 忘记记录题目了有同场次的同学希望可以分享一下
希望来个大佬指正一下第二题哪里有问题
package Huawei; import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner; public class Code1012_002 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m = sc.nextInt(); int n = sc.nextInt(); int x = sc.nextInt(); if(x==0||m==0||n==0){ System.out.println(0); return; } int[][] pass = new int[x][2]; for (int i = 0; i < x; i++) { pass[i][0]= sc.nextInt(); pass[i][1]= sc.nextInt(); } class Customer{ int start; int end; int last ; Customer(int s, int e){ start=s; end = e; last = e-s; } } class CusComp implements Comparator<Customer> { @Override public int compare(Customer a, Customer b) { if(b.last==a.last){ return a.end-b.end; } //小在前大在后 return b.last-a.last ; } } PriorityQueue<Customer> customers= new PriorityQueue<>(new CusComp()); PriorityQueue<Customer> temp= new PriorityQueue<>(new CusComp()); for (int i = 0; i < x; i++) { customers.add(new Customer(pass[i][0],pass[i][1])); } int ans = 0; for (int i = 0; i < m; i++) { if(i>0){ customers = temp; temp=new PriorityQueue<>(new CusComp()); } int start = 10; int end = 0; while(!customers.isEmpty()){ Customer cust = customers.poll(); if((cust.start>=end||cust.end<=start)){ //加进去 if(cust.end>=n){ ans+=(n-1)-(cust.start); }else{ ans+=cust.last; } end = Math.max(end,cust.end); start = Math.min(start,cust.start); }else{ temp.add(cust); } } } System.out.println(ans); } }