1044 拦截导弹

来源:互联网 发布:淘宝智能机器人好用吗 编辑:程序博客网 时间:2024/05/21 02:21

1044 拦截导弹

 

1999年NOIP全国联赛提高组

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
<span style="font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 微软雅黑, 黑体, sans-serif; background-color: rgb(246, 248, 248);">题目描述 </span><small style="font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, 微软雅黑, 黑体, sans-serif; box-sizing: border-box; font-size: 13px; background-color: rgb(246, 248, 248);">Description</small>

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

  

输入描述 Input Description

输入导弹依次飞来的高度(雷达给出的高度数据是不大于30000的正整数)

  

输出描述 Output Description

输出这套系统最多能拦截多少导弹,如果要拦截所有导弹最少要配备多少套这种导弹拦截系统。

样例输入 Sample Input

389 207 155 300 299 170 158 65 

样例输出 Sample Output

6

2

数据范围及提示 Data Size & Hint

导弹的高度<=30000,导弹个数<=20

分类标签 Tags 点此展开 

#include<iostream>using namespace std;int Max(int a[], int n){    int max,i;    max=a[0];    for(i=0;i<n;i++)      {          if(a[i]>max)             max=a[i];      }    return max;}int main(){int high[21],i = 0,n = 0,j;int maxintercept[21],moreintercept[21];;while(cin>>high[n]){maxintercept[n] = 1;moreintercept[n] = 1;n++;}for(i = 0; i < n; i++){for(j = i + 1; j < n; j++){if(high[i] > high[j]){maxintercept[j] = maxintercept[j] < (maxintercept[i]+1)? maxintercept[i]+1:maxintercept[j]; }else{moreintercept[j] = moreintercept[j] < (moreintercept[i]+1)? moreintercept[i]+1:moreintercept[j]; }}}cout<<Max(maxintercept, n)<<endl;cout<<Max(moreintercept, n)<<endl;return 0;}


0 0
原创粉丝点击