poj 2915

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <stack>
#include <vector>
using namespace std;
#define LL long long
const int N = 100005;
vector<LL> arr;
bool vis[N];
void solve()
{
    while (true)
    {
        fill(vis, vis + arr.size(), 0);
        bool f = true;
        for (int i = 0; i < arr.size(); i++)
        {
            if (i > 0 && arr[i] < arr[i - 1])
            {
                vis[i - 1] = vis[i] = 1;
                f = false;
            }
            if (i < arr.size() - 1 && arr[i] > arr[i + 1])
            {
                vis[i + 1] = vis[i] = 1;
                f = false;
            }
        }
        if (f)break;
        for (int i = arr.size() - 1; i >= 0; i--)
        {
            if (vis[i])arr.erase(arr.begin() + i);
        }
    }
}
int main()
{
    freopen("in.txt", "r", stdin);
    freopen("outstd.txt", "w", stdout);
    cin.sync_with_stdio(false);
    LL t, n;
    cin >> t;
    while (t--)
    {
        int id;
        cin >> id;
        cout << id<<':' << endl;
        cin >> n;
        arr.clear();
        for (int i = 0; i < n; i++)
        {
            LL num;
            cin >> num;
            arr.push_back(num);
        }
        solve();
        cout << arr.size() << endl;
        for (int i = 0; i < arr.size(); i++)
            cout << arr[i] << ' ';
        cout << endl;

    }

}

 

posted @ 2016-08-01 09:19  猪突猛进!!!  阅读(151)  评论(0编辑  收藏  举报