https://vjudge.net/contest/68966#problem/I

【题解】

http://www.cnblogs.com/kuangbin/archive/2012/08/03/2621110.html

我们可以把由同一个拦截系统负责打下的导弹归为一组。

假设在输入某一系列的导弹高度中,前N个导弹有X组(即需要X个拦截导弹系统),那么第N+1个导弹无非有两种情况:

1.把这个导弹归到X组中的一组,即不增加拦截系统

2.开启新的一组,即增加一个拦截系统

那么什么时候满足1呢? 就是前X组中有一组的最后一个导弹(即高度最低的导弹)比现在这个第N+1的导弹高度还高。

如 5 2 9 1 最后一个导弹高度为1,那么它可以与5 2同一组,也可以与9同一组

那么什么时候满足2呢?就是前X组中没有一组的最后一个导弹(即高度最低的导弹)比现在这个第N+1的导弹高度还高。

如 5 2 9 10 最后一个导弹的高度为10,因此需要一个新的拦截系统。

这两种情况已经分析完了,考虑一些细节,就是在考虑第一种情况时到底应该将 1 放到哪一组?

其实很简单,如 5 2 9 1 7 如果1与9一组,很明显7将要新的拦截系统。而如果1与5 2一组,那么7就可以与9一组,不需要新的拦截系统。

因为1与9一组时,这组高度最低为1,失去了后面高度为6,5这些高度与9一组的机会。因此归于哪一组时,应计算每一组高度最低的导弹与为归组的导弹的高度差,取高度差最小的一组。

最后就可通过有几组来判定需要几个拦截系统。

【Accepted】

 #include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll; int n;
const int maxn=3e4+;
const int inf=0x3f3f3f3f;
int a[maxn];
int ans[maxn];
int main()
{
while(~scanf("%d",&n))
{
memset(ans,,sizeof(ans));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
int cnt=;
ans[]=a[];
for(int i=;i<=n;i++)
{
int index=-;
int minn=inf;
for(int k=;k<=cnt;k++)
{
if(ans[k]>=a[i]&&ans[k]<minn)
{
minn=ans[k];
index=k;
}
}
if(index==-)
{
ans[++cnt]=a[i];
}
else
{
ans[index]=a[i];
}
}
cout<<cnt<<endl;
}
return ;
}

【贪心】HDU 最少拦截系统的更多相关文章

  1. HDU 1257 最少拦截系统(贪心 or LIS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)   ...

  2. hdu 1257 最少拦截系统【贪心 || DP——LIS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  3. HDU 1257 最少拦截系统 (DP || 贪心)

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  4. hdu 1257 最少拦截系统(动态规划 / 贪心)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)

    Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...

  6. HDU——1257最少拦截系统(贪心)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  7. 【HDU - 1257】最少拦截系统(贪心)

    最少拦截系统 Descriptions: 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的 ...

  8. HDU 1257 最少拦截系统(Dilworth定理+LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  9. HDU1257 最少拦截系统 —— 贪心

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Othe ...

随机推荐

  1. Suricata的性能

    不多说,直接上干货! 见官网 https://suricata.readthedocs.io/en/latest/performance/index.html Docs » 7. Performanc ...

  2. 深入理解spark streaming

    spark streaming是建立在spark core之上的,也就说spark streaming任务最终执行还是依赖于RDD模型.在转化成最终的RDD模型执行前,spark streaming主 ...

  3. PHP使用iconv函数遍历数组转换字符集

    /** * 字符串/二维数组/多维数组编码转换 * @param string $in_charset * @param string $out_charset * @param mixed $dat ...

  4. qconbeijing2018

    https://2018.qconbeijing.com/schedule 会议 · 第一天 (2018/04/20 周五) 时间 日程 上午 主题演讲 大数据下的软件质量建设实践 黄闻欣 出品 人工 ...

  5. 【HEVC帧间预测论文】P1.3 Fast Inter-Frame Prediction Algorithm of HEVC Based on Graphic Information

    基于图形信息的HEVC帧间预测快速算法/Fast Inter-Frame Prediction Algorithm of HEVC Based on Graphic Information <H ...

  6. Oracle EXPDP and IMPDP

    一.特点 • 可通过 DBMS_DATAPUMP 调用 • 可提供以下工具: – expdp – impdp – 基于 Web 的界面 • 提供四种数据移动方法: – 数据文件复制 – 直接路径 – ...

  7. vue项目中快捷语法糖

    1.Vue.js是渐进式框架,采用自底向上增量开发的设计基于MVVM思想. 2.Vue 完全有能力驱动采用单文件组件和Vue生态系统支持的库开发的复杂单页应用. 3.Vue.js 的目标是通过尽可能简 ...

  8. 关于Ubuntu 16.04中E: Could not get lock /var/lib/dpkg/lock - open的三种解决方案

    问题 在Ubuntu中,有时候运用sudo  apt-get install 安装软件时,会出现如下的情况: E: Could not get lock /var/lib/dpkg/lock - op ...

  9. strict说明

  10. EBS ORACLE采购对账单自动产生发票

    只要传入个对账单号,然后跑数据抛到接口表,运行接口请求,就可以自动生成发票 create or replace package body pkg_ap_check_by_po is --创建ap发票 ...