zoukankan      html  css  js  c++  java
  • 2904.最少拦截系统

    /*
    思路:输入一个导弹,与拦截系统比一次,系统数组中是从小到大排序的,从前面开始遇到能拦截的(就是小于拦截系统的)就拦截,系统变换,
    若所有拦截系统都拦截不下,再重新建一个拦截系统。
    */
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 int main()
     6 {
     7    int n;
     8    int a[1024],b[1024];     //a数组保存导弹,b数组保存拦截系统。
     9    while(~scanf("%d",&n))
    10    {
    11        memset(b,0,sizeof(b));
    12        int l=0;
    13        scanf("%d",&a[0]);   //刚开始没有拦截系统,必须先建一个。
    14        b[0]=a[0];
    15        for(int j=1;j<n;j++)
    16        {
    17            scanf("%d",&a[j]);
    18            for(int i=0;i<=l;i++)
    19            {
    20                if(b[i]>=a[j])        //能拦截的就拦截。
    21                {
    22                    b[i]=a[j];
    23                    break;
    24                }
    25                if(b[i]<a[j])            
    26                {
    27                    if(i==l)                 //所有的都不能拦截,再建一个拦截系统。
    28                    {
    29                     l++;
    30                     b[l]=a[j];
    31                    }
    32                    else                    //这个拦截系统不行,换下一个。
    33                    continue;
    34                }
    35            }
    36        }
    37          //for(int i=0;i<=l;i++)
    38             //printf("%d ",b[i]);
    39        printf("%d
    ",l+1);
    40    }
    41    return 0;
    42 }

     

  • 相关阅读:
    Octave/Matlab初步学习
    week_3
    week_2
    week_1
    清除input[type=number]的默认样式
    js,获取和设置cookie、 localStorage
    php表单提交时获取不到post数据的解决方法
    console.log 简写
    JS合并两个数组的方法
    javascript ES5、ES6的一些知识
  • 原文地址:https://www.cnblogs.com/zou-zou/p/5392754.html
Copyright © 2011-2022 走看看