DAYSIX_PAT(乙级)1015.德才论

1015.德才论
纠结了很久,一直在想最干净明了的办法,但是这个思路在PAT上会有三个测试点运行超时,我看了牛客网其他java选手的代码也是那三个测试点超时。代码仅供参考。
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/**
 * 德才论
 * 重写java集合的排序方法
 */
class Person implements Comparable{
	String NO="";
	int D=0;
	int C=0;
	int sum=D+C;
	@Override
	public int compareTo(Person p) {
		int i=p.sum-this.sum;
		if(i==0) {
			i=p.D-this.D;
		}
		if(i==0) {
			i=this.NO.compareTo(p.NO);
		}
		return i;
	}	
}
public class Main{

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		int L=in.nextInt();
		int H=in.nextInt();
		ArrayList DAC=new ArrayList();
		ArrayList Dc=new ArrayList();
		ArrayList dc=new ArrayList();
		ArrayList other=new ArrayList();
		
		for(int i=0;i=H && p.C>=H) {
				DAC.add(p);
			} else if (p.D>=H && p.C>=L) {
				Dc.add(p);
			} else if (p.D>=L && p.C>=L && p.D>p.C) {
				dc.add(p);
			} else if (p.D>=L && p.C>=L) {
				other.add(p);
			}
		}
		
		int count=DAC.size()+Dc.size()+dc.size()+other.size();
		System.out.println(count);
		Collections.sort(DAC);
		Collections.sort(Dc);
		Collections.sort(dc);
		Collections.sort(other);
		for(int i=0;i

你可能感兴趣的:(算法)