JZOJ10004 列车调度

博客围绕JZOJ100041列车调度题目展开,给出了输入输出示例。题解指出每个列车序列需单调递减,对于每个列车,应贪心选择在其前面比它大的最小列车,可使用set实现,题解转载自相关博客。

【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;
}

 

转载于:https://www.cnblogs.com/renjianshige/p/9562630.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值