IT民工
加油!

  这道题是求一个最长下降子序列,onlogn)的算法也不难写,仿照最长升序子序列的写法,

还好二分没写成死循环。这题输入比较坑爹,每组测试以-1结尾,结束所有测试也是-1,然后要

求没两组之间有空行,在测试的时候看到的是输入每组第一个数才空行,这里浪费了不少时间

 

/*Accepted 168K 0MS C++ 627B 2012-04-22 18:33:00 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define MAXN 32900
int a[MAXN], t;
int main()
{
    int top, n, i, T = 0;
    while( scanf( "%d", &t), t!= -1)
    {
        if( T) printf( "\n");
        top = 1;
        a[top ++] = t;
        do{
            if( t < a[top - 1])
                a[top ++] = t;
            else {
                int l = 1, r = top - 1;
                while( l <= r)
                {
                    int mid = (l + r) >> 1;
                    if( a[mid] > t)
                        l = mid + 1;
                    else r = mid - 1;
                }
                a[l] = t;
                scanf( "%d", &t);
            }
        }while( t != -1);
        printf( "Test #%d:\n", ++ T);
        printf( "  maximum possible interceptions: %d\n", top - 1);
    }
    return 0;
}

 

 

 

   

posted on 2012-04-22 18:40  找回失去的  阅读(221)  评论(0)    收藏  举报