zoukankan      html  css  js  c++  java
  • 10901 Missile

    10901 Missile

    时间限制:1000MS  内存限制:65535K
    提交次数:40 通过次数:7

    Description

    Long, long ago, country A invented a missile system to destroy the missiles from their enemy. That system can launch only one missile to destroy multiple missiles if the heights of all the missiles form a non-decrease sequence.

    But recently, the scientists found that the system is not strong enough. So they invent another missile system. The new system can launch one single missile to destroy many more enemy missiles. Basically, the system can destroy the missile from near to far. When the system

    is begun, it chooses one enemy missile to destroy, and then destroys a missile whose height is lower and farther than the first missile. The third missile to destroy is higher and farther than the second missile... the odd missile to destroy is higher and farther than the previous one, and the even missile to destroy is lower and farther than the previous one.

    Now, given you a list of the height of missiles from near to far, please find the most missiles that can be destroyed by one missile launched by the new system.

    输入格式

    The input contains multiple test cases.

    In each test case, first line is an integer n (0<n≤1000), which is the number of missiles to destroy. Then follows one line which contains n integers (≤109), the height of the missiles followed by distance.

    The input is terminated by n=0.

    输出格式

    For each case, print the most missiles that can be destroyed in one line.

    输入样例

    4
    5 3 2 4
    3
    1 1 1
    0

    输出样例

    3
    1

    题意:

      n代表导弹数目,然后从高到远给出导弹的高度,

      求最多能打下导弹个数,比且打下来的第偶数个导弹要比前一个矮且远,第奇数个导弹要比前一个

      高且远。

     
    DP题:
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 int dp[1010],a[1010];
     4 
     5 int max(int a,int b)
     6 {
     7     return a>b?a:b;
     8 }
     9 
    10 int main()
    11 {
    12      int n,i,t,j;
    13      while(scanf("%d",&n)&&n)
    14      {
    15 
    16           for(i=0;i<n;i++){
    17               scanf("%d",&a[i]);
    18               dp[i]=1;
    19           }
    20 
    21           for(i=1,t=1; i<n; i++)
    22           {
    23                 for(j=0;j<i;j++)
    24                    if((dp[j]%2==1&&a[i]<a[j])||(dp[j]%2==0&&a[i]>a[j]))
    25                        dp[i]=max(dp[j]+1,dp[i]);
    26                 t=max(t,dp[i]);
    27           }
    28            printf("%d
    ",t);
    29      }
    30 
    31      return 0;
    32 }
  • 相关阅读:
    七、AOP统一处理以及日志打印
    六、spring Boot项目表单验证(最小值为例)以及spring的常用注解
    五、spring-data-Jpa 数据库操作
    四、spring Boot项目中Controller的使用
    三、SpringBoot的常用配置(.yml通过配置文件和注解进行属性注入,以及分别配置生产、开发环境)
    机器学习中的 上采样 下采样 过采样 欠采样
    Mac 安装/卸载 brew
    Keras 训练自己的人脸特征点提取模型的坑
    Keras 使用自己编写的数据生成器
    iPhone 设备管理在哪(已解决)
  • 原文地址:https://www.cnblogs.com/zyx1314/p/3533624.html
Copyright © 2011-2022 走看看