zoukankan      html  css  js  c++  java
  • Alignment

    Alignment

    Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u

    Description

    In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; it is true that the soldiers are aligned in order by their code number: 1 , 2 , 3 , . . . , n , but they are not aligned by their height. The captain asks some soldiers to get out of the line, as the soldiers that remain in the line, without changing their places, but getting closer, to form a new line, where each soldier can see by looking lengthwise the line at least one of the line's extremity (left or right). A soldier see an extremity if there isn't any soldiers with a higher or equal height than his height between him and that extremity.

    Write a program that, knowing the height of each soldier, determines the minimum number of soldiers which have to get out of line.

    Input

    On the first line of the input is written the number of the soldiers n. On the second line is written a series of n floating numbers with at most 5 digits precision and separated by a space character. The k-th number from this line represents the height of the soldier who has the code k (1 <= k <= n).

    There are some restrictions:
    • 2 <= n <= 1000
    • the height are floating numbers from the interval [0.5, 2.5]

    Output

    The only line of output will contain the number of the soldiers who have to get out of the line.

    Sample Input

    8
    1.86 1.86 1.30621 2 1.4 1 1.97 2.2
    

    Sample Output

    4

    http://blog.csdn.net/lanjiangzhou/article/details/8993095

    我又醉了,为啥感觉一样的代码,除了复制,就是一个wa,一个ac,,受不鸟

    直接粘好了:
    #include<iostream>
    #include<cstring>
    #include<stdio.h>
    using namespace std;
    #define MAXN 1010
    double s[MAXN];
    int a[MAXN],b[MAXN];
    int n;
    int main()
    {
     while(cin>>n)
     {
      int i,j;
      for(i=1;i<=n;i++)
       scanf("%lf",&s[i]);
      a[1]=1;
      for(i=2;i<=n;i++)//从头开始计算最长的递增序列
      {
       a[i]=1;
       for(j=1;j<i;j++)
       {
        if(s[i]>s[j]&&a[j]>=a[i])
         a[i]=a[j]+1;
       }
      }
      b[n]=1;
      for(i=n-1;i>=1;i--)//从尾部计算最长的递增序列
      {
       b[i]=1;
       for(j=n;j>i;j--)
       {
        if(s[i]>s[j]&&b[j]>=b[i])
         b[i]=b[j]+1;
       }
      }
      int max=-100000;//初始化max
      for(i=1;i<=n;i++)
      {
       for(j=i+1;j<=n;j++)
       {
        if(a[i]+b[j]>max)
         max=a[i]+b[j];
       }
      }
      printf("%d ",n-max);
     }
     return 0;
    }
    链接:http://blog.csdn.net/dangwenliang/article/details/5728363
    IDEAS:
    对于英文题,就是要一个词一个词的扣意思,对于像我这种最不爱扣意思的人是大忌。所以才有了,什么不踏实之类的说法。
    不要想当然don't take it for granted,理解好题意是根本,基础。
    本题:就是说任何一个士兵向某一个方向(left or right看,都没有超过他height的人。呃, 这是什么意思,最长子序列?是,但貌似又没有那么简单。
    还请看:http://blog.csdn.net/lanjiangzhou/article/details/8993095

    题意:令到原队列的最少士兵出列后,使得新队列任意一个士兵都能看到左边或者右边的无穷远处。就是使新队列呈三角形分布就对了。即左边的递增序列人数和右边的递减序列人数之和最大因而可转化为求“最长不降子序列”和“最长不升子序列”问题。进一步转化为从头部求出最长不下降子序列与从尾部求出最长不下降子序列即可,分别求出二者的大小,最后用队列长度减去二者之和就是我们所求的出列的士兵个数。
    //最长单调子序列,看清题意,从左边求上升,从右边求下降,然后相加,注意中间两个点的高度可以相同
    //思路:用了两个LIS分别从前往后和从后往前,得到啊a[],b[],最后取a[i]+b[i]的最大值;
    让未来到来 让过去过去
  • 相关阅读:
    Nginx详解十四:Nginx场景实践篇之代理服务
    PyCharm设置字体风格
    PyCharm+SVN
    Nginx详解十三:Nginx场景实践篇之防盗链
    Nginx详解十二:Nginx场景实践篇之跨站访问相关
    Nginx详解十一:Nginx场景实践篇之Nginx缓存
    Nginx详解十:Nginx场景实践篇之Nginx静态资源场景配置
    Nginx详解九:Nginx基础篇之Nginx的访问控制
    浅谈控件(组件)制作方法一(附带一delphi导出数据到Excel的组件实例)(原创)
    切断数据感知控件,大大提升软件运行速度
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4466484.html
Copyright © 2011-2022 走看看