set 容器的巧妙利用
来源:互联网 发布:windows 官网 编辑:程序博客网 时间:2024/06/06 02:09
Egg pain's hzf
Time Limit: 3000MS Memory Limit: 65535KBSubmissions: 45 Accepted: 10
Sample Input
51 2 3 4 55 5 4 3 2 1
Sample Output
-1 1 2 3 4
-1 -1 -1 -1 -1
这题一开始我直接暴力,发现超时,其实想都不要想,两个for直接肯定会超时,然后想不到方法了,后来队长教我了:
#include <iostream>#include <cstdio>#include <cstring>#include <set>#include <algorithm>using namespace std;const int N=100005;int a[N];int n;int main() { int b; while(scanf("%d",&n)!=EOF) { set<int>M; set<int>::iterator it; for(int i=0; i<n; i++) { scanf("%d",&a[i]); int k=a[i]; it=M.lower_bound(a[i]); if(it==M.begin())a[i]=-1; else { --it; a[i]=*it; } M.insert(k); } printf("%d",a[0]); for(int i=1; i<n; i++) { printf(" %d",a[i]); } printf("\n"); } return 0;}
0 0
- set 容器的巧妙利用
- 巧妙解析JAVA中容器的概念
- set容器的实现
- set容器的排序
- SET容器的基本知识
- set容器的查找
- set容器的用法
- 容器set的使用
- set容器的erase
- set容器的用法
- Set容器的使用
- 巧妙利用图片IMG的onerror事件
- set容器的常用方法
- 容器set/multiset的使用方法
- C++---set容器的用法
- Set容器的排序规则
- 浅谈STL的set容器
- Java容器Set的使用
- 该死的发个史蒂夫个
- ubuntu13.10: google chrome can not be run as root
- Unity3d中有关游戏角色控制的几种实现方式
- 在windows xp下利用Eclipse构建Mahout
- linux 后台执行oracle sql脚本
- set 容器的巧妙利用
- PB_删除实现方法
- mysql数据库在命令行的导入导出
- 使用KineticJS HTML5画布修改曲线锚点
- Solution of issue: Android soft keyboard overlap with input div on browser【Android虚拟键盘与输入框重叠解决方案】
- final 关键字
- GCC 编译c程序的方法及过程解析
- 【知识点】Filter、Servlet、Listener区别与联系
- Incorrect column specifier for column 'addressId'