hdu 1257

http://acm.hdu.edu.cn/showproblem.php?pid=1257

题意:有个拦截系统,这个系统在最开始可以拦截任意高度的导弹,但是之后只能拦截不超过这个导弹高度的导弹,现在有N个导弹需要拦截,问你最少需要多少个拦截系统

思路:按高度由大到小进行排序,然后在遍历这个,用一个数组继续每个导弹拦截系统可以拦截的最低高度,如果发现当前的点需要在所以的拦截系统拦截的最低高度之前,那么在加一个拦截系统

 1 import java.awt.Point;
 2 import java.io.BufferedReader;
 3 import java.io.File;
 4 import java.io.FileNotFoundException;
 5 import java.io.FileOutputStream;
 6 import java.io.IOException;
 7 import java.io.InputStream;
 8 import java.io.InputStreamReader;
 9 import java.io.OutputStream;
10 import java.io.PrintStream;
11 import java.lang.reflect.Array;
12 import java.math.BigInteger;
13 import java.util.Arrays;
14 import java.util.Comparator;
15 import java.util.Random;
16 import java.util.Scanner;
17 import java.util.StringTokenizer;
18 
19 public class Main {
20     public static void main(String[] args) throws FileNotFoundException{
21     //    InputReader cin = new InputReader(System.in);
22         Scanner cin = new Scanner(System.in);
23         int t;
24         Point p[] = new Point[20005];
25         for(int i =0;i<20005;i++)
26             p[i] = new Point();
27         int cnt[] = new int[20005];
28         while(cin.hasNext()){
29             t = cin.nextInt();
30             for(int i =0;i<t;i++){
31                 p[i].x = cin.nextInt();
32                 p[i].y = i;
33             }
34             Arrays.sort(p,0,t,new zxc());
35             cnt[0] = p[0].y;
36             int res = 1;
37             for(int i = 1,j;i<t;i++){
38             //    System.out.println(p[i].x+"   "+p[i].y);
39                 for(j = 0;j<res;j++){
40                     if(p[i].y>cnt[j]){
41                         cnt[j] = p[i].y;
42                         break;
43                     }
44                 }
45                 if(j==res){
46                     cnt[res++] = p[i].y;
47                 }
48             }
49             System.out.println(res);
50         }
51     }
52 }
53 
54 
55 class zxc implements Comparator<Point>{
56 
57     
58     public int compare(Point a, Point b) {
59         if(a.x==b.x)
60             return a.y-b.y;
61         return b.x-a.x;
62     }
63     
64 }
原文地址:https://www.cnblogs.com/Tree-dream/p/7451790.html