标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 43909 Accepted Submission(s): 23436
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class Main { public static void sort( List<Obj> list ) { Collections.sort( list, new Comparator<Obj>() { public int compare( Obj o1, Obj o2 ) { return o1.end - o2.end; } } ); } public static void main( String[] args ) { List<Obj> list; Scanner sc = new Scanner(System.in); int n; while(sc.hasNext()){ n = sc.nextInt(); if(n==0) return; list = new ArrayList<Obj>(); while(n>0){ int start = sc.nextInt(); int end = sc.nextInt(); Obj obj = new Obj( start, end, end-start ); list.add( obj ); n--; sort(list); } System.out.println(solve(list)); } } private static int solve( List<Obj> list ) { int max = 1; int end = list.get(0).end; for(int i=0;i<list.size();i++){ if(list.get( i ).start >= end){ end = list.get( i ).end; max++; } } return max; } } class Obj { public int start; public int end; public int dur; public Obj( int start, int end, int dur ) { this.start = start; this.end = end; this.dur = dur; } }
标签:
原文地址:http://www.cnblogs.com/dick159/p/5438093.html