• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj1836

            Alignment

            Time Limit: 1000MS Memory Limit: 30000K
            Total Submissions: 7642 Accepted: 2434

            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
            一些士兵站成一排,現(xiàn)在要盡量少的士兵出來,使得剩些的士兵都能看到排左或排右,看到的意思是,中間沒有比它高的
            這個題和合唱隊形差不多,但是有區(qū)別,中間的兩個人可以一樣高
            從左到右求最長上升子序列,再右到左求最長上升子序列,
            然后枚舉中間節(jié)點,求兩個序列的最大和
            中間兩個一樣高可以,需要特別處理下
             1#include<stdio.h>
             2#include<string.h>
             3#include<math.h>
             4#define eps 0.0000001
             5#define MAX 1005
             6double a[MAX];
             7int f[MAX],f1[MAX];
             8int n,i,j,ans;
             9int max(int a,int b)
            10{
            11    if (a>b) return a;
            12    else return b;
            13}

            14int main()
            15{
            16    scanf("%d",&n);
            17    for (i=1; i<=n ; i++ ) scanf("%lf",&a[i]);
            18    f[1]=1;
            19    for (i=2; i<=n ; i++ )
            20    {
            21        f[i]=1;
            22        for (j=1; j<=i-1 ; j++ )
            23        {
            24            if ((a[i]-a[j])>eps)
            25            {
            26                f[i]=max(f[j]+1,f[i]);
            27            }

            28        }

            29    }

            30    f1[n]=1;
            31    for (i=n-1; i>=1 ; i-- )
            32    {
            33        f1[i]=1;
            34        for (j=n; j>=i+1 ; j-- )
            35        {
            36            if ((a[i]-a[j])>eps)
            37            {
            38                f1[i]=max(f1[i],f1[j]+1);
            39            }

            40        }

            41    }

            42    ans=0;
            43    for (i=1; i<=n ; i++ )
            44    {
            45        ans=max(ans,f[i]+f1[i]-1);
            46        for (j=i+1;j<=n ;j++ )
            47        {
            48            if ((a[i]-a[j])<eps)
            49            {
            50                if (ans<f[i]+f1[j])
            51                {
            52                    ans=f[i]+f1[j];
            53                }

            54                else break;
            55            }

            56        }

            57    }

            58    printf("%d\n",n-ans);
            59    return 0;
            60}

            61///合唱隊形類似
            62
             

            posted on 2012-02-21 13:12 jh818012 閱讀(153) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統(tǒng)計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點擊標題查看
            • --王私江
            97久久超碰国产精品旧版| 久久激情五月丁香伊人| 国产亚洲精久久久久久无码AV| 日本精品久久久中文字幕| 精品国产91久久久久久久a| 久久人人爽人人爽人人片av麻烦| 国产成人精品综合久久久| 久久伊人五月天论坛| 久久er国产精品免费观看2| 69久久夜色精品国产69| 日韩乱码人妻无码中文字幕久久 | 亚洲av伊人久久综合密臀性色 | 色成年激情久久综合| 97久久综合精品久久久综合| 亚洲国产成人精品久久久国产成人一区二区三区综 | 99久久人妻无码精品系列| 精品国产91久久久久久久 | 亚洲精品乱码久久久久久蜜桃不卡 | 久久精品一区二区三区中文字幕 | 亚洲国产精品无码久久久秋霞2| 久久久久人妻精品一区二区三区| 国产成人精品久久亚洲| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 人妻无码精品久久亚瑟影视 | 久久久无码精品午夜| 久久99热精品| 久久久久人妻一区二区三区vr| 久久这里都是精品| 久久香蕉国产线看观看猫咪?v| 久久亚洲精品中文字幕| 亚洲中文字幕无码久久2017| 一级a性色生活片久久无少妇一级婬片免费放 | 欧美与黑人午夜性猛交久久久| 亚洲国产精品久久久久婷婷老年| 久久99精品久久久久婷婷| 久久久噜噜噜久久熟女AA片| 精品久久久久久国产| 天天躁日日躁狠狠久久| 精品综合久久久久久888蜜芽| 久久精品国产亚洲αv忘忧草 | 伊人久久大香线蕉综合Av|