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.pswp.cn/news/391547.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391547.shtml
英文地址,請注明出處:http://en.pswp.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…