JZOJ10004 列车调度

【JZOJ100041】列车调度

Description

Pic

Input

Output

Sample Input

Sample1:
3
1 2 3

Sample2:
9
1 3 2 4 8 6 9 5 7

Sample Output

Sample1:
3

Sample2:
5

Hint

Pic

 

题解:

  这个题目,我们手玩可以发现,每个列车的序列必须要保证单调递减,对于每个列车,我们贪心的选择,在他前面的比他大的最小的列车.用set实现就可以了.

 

题解:

  

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <set>
#define MAXN 100010
using namespace std;
int n;
set<int> s;
set<int>::iterator it;

int main()
{
    freopen("1.in","r",stdin);
    freopen("1.out","w",stdout);
    scanf("%d",&n);int ans=0;
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);s.insert(x);
        it=s.find(x);
        if(++it!=s.end()) s.erase(it);
        else ans++;
    }
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2018-08-30 20:47  人间失格—太宰治  阅读(119)  评论(0编辑  收藏  举报