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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391547.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

eda可视化_5用于探索性数据分析(EDA)的高级可视化

eda可视化Early morning, a lady comes to meet Sherlock Holmes and Watson. Even before the lady opens her mouth and starts telling the reason for her visit, Sherlock can tell a lot about a person by his sheer power of observation and deduction. Similarly, we…

我的AWS开发人员考试未通过。 现在怎么办?

I have just taken the AWS Certified Developer - Associate Exam on July 1st of 2019. The result? I failed.我刚刚在2019年7月1日参加了AWS认证开发人员-联考。结果如何&#xff1f; 我失败了。 The AWS Certified Developer - Associate (DVA-C01) has a scaled score …

关系数据可视化gephi

表示对象之间的关系&#xff0c;可通过gephi软件实现&#xff0c;软件下载官方地址https://gephi.org/users/download/ 如何来表示两个对象之间的关系&#xff1f; 把对象变成点&#xff0c;点的大小、颜色可以是它的两个参数&#xff0c;两个点之间的关系可以用连线表示。连线…

Hyperledger Fabric 1.0 从零开始(十二)——fabric-sdk-java应用

Hyperledger Fabric 1.0 从零开始&#xff08;十&#xff09;——智能合约&#xff08;参阅&#xff1a;Hyperledger Fabric Chaincode for Operators——实操智能合约&#xff09; Hyperledger Fabric 1.0 从零开始&#xff08;十一&#xff09;——CouchDB&#xff08;参阅&a…

css跑道_如何不超出跑道:计划种子的简单方法

css跑道There’s lots of startup advice floating around. I’m going to give you a very practical one that’s often missed — how to plan your early growth. The seed round is usually devoted to finding your product-market fit, meaning you start with no or li…

将json 填入表格_如何将Google表格用作JSON端点

将json 填入表格UPDATE: 5/13/2020 - New Share Dialog Box steps available below.更新&#xff1a;5/13/2020-下面提供了 新共享对话框步骤。 Thanks Erica H!谢谢埃里卡H&#xff01; Are you building a prototype dynamic web application and need to collaborate with …

leetcode 173. 二叉搜索树迭代器

实现一个二叉搜索树迭代器类BSTIterator &#xff0c;表示一个按中序遍历二叉搜索树&#xff08;BST&#xff09;的迭代器&#xff1a; BSTIterator(TreeNode root) 初始化 BSTIterator 类的一个对象。BST 的根节点 root 会作为构造函数的一部分给出。指针应初始化为一个不存在…

jyputer notebook 、jypyter、IPython basics

1 、修改jupyter默认工作目录&#xff1a;打开cmd&#xff0c;在命令行下指定想要进的工作目录&#xff0c;即键入“cd d/ G:\0工作面试\学习记录”标红部分是想要进入的工作目录。 2、Tab补全 a、在命令行输入表达式时&#xff0c;按下Tab键即可为任意变量&#xff08;对象、…

cookie和session(1)

cookie和session 1.cookie产生 识别用户 HTTP是无状态协议&#xff0c;这就回出现这种现象&#xff1a;当你登录一个页面&#xff0c;然后转到登录网站的另一个页面&#xff0c;服务器无法认识到。或者说两次的访问&#xff0c;服务器不能认识到是同一个客户端的访问&#xff0…

熊猫数据集_为数据科学拆箱熊猫

熊猫数据集If you are already familiar with NumPy, Pandas is just a package build on top of it. Pandas provide more flexibility than NumPy to work with data. While in NumPy we can only store values of single data type(dtype) Pandas has the flexibility to st…

2018年,你想从InfoQ获取什么内容?丨Q言Q语

- Q 言 Q 语 第 三 期 - Q言Q语是 InfoQ 推出的最新板块&#xff0c; 旨在给所有 InfoQer 一个展示观点的平台。 每期一个主题&#xff0c; 不扣帽子&#xff0c;不论对错&#xff0c;不看输赢&#xff0c; 只愿跟有趣的灵魂相遇。 本期话题&#xff1a; 2018年&#xff0c;你想…

特征阻抗输入阻抗输出阻抗_软件阻抗说明

特征阻抗输入阻抗输出阻抗by Milan Mimica米兰米米卡(Milan Mimica) 软件阻抗说明 (Software impedance explained) 数据处理组件之间的阻抗不匹配 (The impedance mismatch between data processing components) It all starts with the simplest signal-processing diagram …

数学建模3

数学建模3 转载于:https://www.cnblogs.com/Forever77/p/11423169.html

leetcode 190. 颠倒二进制位(位运算)

颠倒给定的 32 位无符号整数的二进制位。 提示&#xff1a; 请注意&#xff0c;在某些语言&#xff08;如 Java&#xff09;中&#xff0c;没有无符号整数类型。在这种情况下&#xff0c;输入和输出都将被指定为有符号整数类型&#xff0c;并且不应影响您的实现&#xff0c;因…

JAVA基础——时间Date类型转换

在java中有六大时间类&#xff0c;分别是&#xff1a; 1、java.util包下的Date类&#xff0c; 2、java.sql包下的Date类&#xff0c; 3、java.text包下的DateFormat类&#xff0c;&#xff08;抽象类&#xff09; 4、java.text包下的SimpleDateFormat类&#xff0c; 5、java.ut…

LeetCode第五天

leetcode 第五天 2018年1月6日 22.(566) Reshape the Matrix JAVA class Solution {public int[][] matrixReshape(int[][] nums, int r, int c) {int[][] newNums new int[r][c];int size nums.length*nums[0].length;if(r*c ! size)return nums;for(int i0;i<size;i){ne…

matplotlib可视化_使用Matplotlib改善可视化设计的5个魔术技巧

matplotlib可视化It is impossible to know everything, no matter how much our experience has increased over the years, there are many things that remain hidden from us. This is normal, and maybe an exciting motivation to search and learn more. And I am sure …

adb 多点触碰_无法触及的神话

adb 多点触碰On Twitter, in Slack, on Discord, in IRC, or wherever you hang out with other developers on the internet, you may have heard some formulation of the following statements:在Twitter上&#xff0c;在Slack中&#xff0c;在Discord中&#xff0c;在IRC…

robot:循环遍历数据库查询结果是否满足要求

使用list类型变量{}接收查询结果&#xff0c;再for循环遍历每行数据&#xff0c;取出需要比较的数值 转载于:https://www.cnblogs.com/gcgc/p/11424114.html

leetcode 74. 搜索二维矩阵(二分)

编写一个高效的算法来判断 m x n 矩阵中&#xff0c;是否存在一个目标值。该矩阵具有如下特性&#xff1a; 每行中的整数从左到右按升序排列。 每行的第一个整数大于前一行的最后一个整数。 示例 1&#xff1a; 输入&#xff1a;matrix [[1,3,5,7],[10,11,16,20],[23,30,34…