HDU 4604 Deque

来源:互联网 发布:js输入框输入触发事件 编辑:程序博客网 时间:2024/05/20 23:36

!!流弊的方法

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <queue>using namespace std;const int inf = 0x3f3f3f3f;const int M = 100011;int n;int a[M];vector<int>v;inline void gao(int now){    if (v.empty() || now >= v[v.size() - 1])    {        v.push_back(now);    }    else    {        v[upper_bound(v.begin(), v.end(), now) - v.begin()] = now;  //二分查找替换    }}int main(){    int T;    cin >> T;    while (T--)    {        cin >> n;        for (int i = 1; i <= n; i++)        {            //cin >> a[i];            scanf("%d",&a[i]);        }        v.clear();        int now;        for (int i = n; i >= 1; i--)          {            now = a[i]*2+1 ;   //避免重复              gao(now);        }        for (int i = 1; i <= n; i++)        {            now =  a[i]*2;            gao(now);        }//        for(int i=0; i<v.size(); ++i)//        {//            cout<<v[i]<<" ";////        }////        puts("");        cout << v.size() << endl;    }    return 0;}

0 0
原创粉丝点击