博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[set] Jzoj P100041 列车调度
阅读量:4696 次
发布时间:2019-06-09

本文共 722 字,大约阅读时间需要 2 分钟。

Description

 

Input

Output

 

Sample Input

Sample1:31 2 3Sample2:91 3 2 4 8 6 9 5 7

Sample Output

Sample1:3Sample2:5
 

Data Constraint

 

 

题解

  • 题目要求的是最小的轨道数,那么肯定一条轨道停多几列要比新开一条轨道要优
  • 那么只有后进来的列车x要比之前在轨道的最后一列列车的编号要小才能停
  • 显然,每次要找到比x大的最小值对吧
  • 然后,就可以用set来维护每个铁轨最后一列列车的编号

代码

1 #include 
2 #include
3 #include
4 using namespace std; 5 set
Q; 6 int n,x; 7 int main() 8 { 9 scanf("%d%d",&n,&x); Q.insert(x);10 for(int i=2;i<=n;i++)11 {12 scanf("%d",&x);13 if (x<*Q.rbegin()) Q.erase(*(Q.upper_bound(x)));14 Q.insert(x);15 }16 printf("%d",Q.size());17 return 0;18 }

 

转载于:https://www.cnblogs.com/Comfortable/p/9502303.html

你可能感兴趣的文章
我的linuxES
查看>>
FileReader文件读取API
查看>>
UVa 11300 Spreading the Wealth 分金币
查看>>
[leetcode] Happy Number
查看>>
Java第五周学习总结
查看>>
j.c.Warnsdorff马踏棋盘算法
查看>>
git私服
查看>>
the openning
查看>>
python 字符串 和 print
查看>>
MAC OS下安装Minizip
查看>>
Java_Certificates does not conform to algorithm constraints
查看>>
box-shadow
查看>>
字符串截取
查看>>
PAT 1027. Colors in Mars
查看>>
linux定时执行脚本
查看>>
Oauth支持的5类 grant_type 及说明
查看>>
java 导出Excel 大数据量,自己经验总结!(二)
查看>>
ASP.NET 5 DNX SDK删除旧版本
查看>>
购物车小程序
查看>>
jQuery添加方法
查看>>