1322:拦截导弹问题(Noip1999)

【题目描述】

某国为了防御敌国的导弹袭击,开发出一种导弹拦截系统,但是这种拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭,由于该系统还在试用阶段。所以一套系统有可能不能拦截所有的导弹。

输入导弹依次飞来的高度(雷达给出的高度不大于30000的正整数)。计算要拦截所有导弹最小需要配备多少套这种导弹拦截系统。

【输入】

n颗依次飞来的高度(1≤n≤1000)。

【输出】

要拦截所有导弹最小配备的系统数k。

【输入样例】

389 207 155 300 299 170 158 65

【输出样例】

2

【提示】

输入:导弹高度: 4  3  2

输出:导弹拦截系统k=1

// Created on 2020/2/12

/*#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <climits>*/
#include <bits/stdc++.h>

using namespace std;

const int idata=1000+5;
int goal[idata];
int step[idata];
int n,m;
int flag;
int cnt;
int ans=1;
int maxx=0;

int main()
{
    int i,j;
    while(scanf("%d",&n)!=EOF)
        goal[cnt++]=n;

    step[1]=goal[0];
    for(i=1;i<cnt;i++)
    {
        flag=0;
        maxx=0;
        for(j=1;j<=ans;j++)
        {
            if(!flag)
            {
                if(step[j]>=goal[i])//不高于前一发,所以“大于等于”
                {
                    flag=j;
                    maxx=step[j];
                }
            }

            if(flag)
            {
                if(maxx>step[j])
                {
                    flag=j;
                    maxx=step[j];
                }
            }
        }
        if(flag)
            step[flag]=goal[i];
        if(!flag)
            step[++ans]=goal[i];
    }

    cout<<ans<<endl;
    /*for(i=1;i<=ans;i++)
    {
        cout<<step[i]<<endl;
    }*/
}
发布了177 篇原创文章 · 获赞 8 · 访问量 6337

猜你喜欢

转载自blog.csdn.net/C_Dreamy/article/details/104282583