POJ 3903 Stock Exchange

最长递增序列

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int tmp[100010],lt;
int main()
{
    int n,i,j,mi,ma,mid,t;
    while (scanf("%d",&n) != EOF)
    {
        lt=0;
        tmp[lt]=-99999999;
        for (i=0; i<n; i++)
        {
      	    scanf("%d",&t);
            if (t > tmp[lt])
            {
                lt++;
                tmp[lt]=t;
            }
            else
            {
                mi=1;
                ma=lt;
                mid=(mi+ma)>>1;
                while (mi <= ma)
                {
                    mid=(mi+ma)>>1;
                    if (tmp[mid] < t)
                    {
                        mi=mid+1;
                    }
                    else
                    {
                        ma=mid-1;
                    }
                }
                tmp[mi]=t;
            }
        }
        printf("%d\n",lt);
    }
}


你可能感兴趣的:(POJ 3903 Stock Exchange)