zoukankan      html  css  js  c++  java
  • hdu dp 1257 最小拦截系统


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

    Description

    某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 
    怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统. 

    Input

    输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔) 

    Output

    对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统. 

    Sample Input

    8 389 207 155 300 299 170 158 65

    Sample Output

    2

    #include<stdio.h>
    #include<math.h>
    int a[30001],b[30001];
    int main()
    {
        int n,i,j,k;
        while(scanf("%d",&n)!=EOF)
        {
            b[0]=0;
            k=0;
            for(i=0; i<n; i++)
            {
                scanf("%d",&a[i]);
                for(j=0; j<=k; j++)
                {
                    if(a[i]<b[j])
                    {
                        b[j]=a[i];
                        break;//如果后面的高度比前面的小,则把后面的代替前面的。
                    }
                    else if(j==k)
                    {
                        k++;//当后面的高度比前面各系统的最小高度都大时,则系统增加1,此时此系统的最小高度为当前值。
                        b[k]=a[i];
                        break;
                    }
                }
            }
            printf("%d
    ",k);
        }
        return 0;
    }
    
    
    
    ////贪心写法
    //#include <iostream>
    //#include <algorithm>
    //
    //using namespace std;
    //
    //const int MAX_N = 10000;
    //int n;
    //int temp[MAX_N];
    //
    //int main()
    //{
    //    while(cin >> n)
    //    {
    //        int k = 0;
    //        bool flag = false;
    //        int height;
    //        cin >>height;
    //        temp[0] = height;
    //        k++;
    //        for(int i = 1; i < n; i++)
    //        {
    //            flag = false;
    //            cin >> height;
    //            //sort(temp,temp + k);
    //            for(int j = 0; j < k; j++)
    //            {
    //                if(temp[j] > height)
    //                {
    //                    temp[j] = height;
    //                    flag = true;
    //                    break;
    //                }
    //            }
    //            if(!flag)
    //                temp[k++] = height;
    //        }
    //        cout << k << endl;
    //    }
    //    return 0;
    //}
    //
    //
    //
    //
    
    

  • 相关阅读:
    天梯赛5-12 愿天下有情人都是失散多年的兄妹 【dfs】
    poj2718 Smallest Difference【贪心】
    HDU problem 5635 LCP Array【思维】
    codeforces 782C Andryusha and Colored Balloons【构造】
    HDU 4278 Faulty Odometer【进制转换】
    codeforces B. The Meeting Place Cannot Be Changed【二分】
    POJ 3264 Balanced Lineup 【线段树】
    HDU 1850
    CodeForces-714C
    HDU Problem 1247 Hat's Words 【字典树】
  • 原文地址:https://www.cnblogs.com/nyist-xsk/p/7264905.html
Copyright © 2011-2022 走看看