Time limit(ms): 3000    Memory limit(kb): 65535
 

hzf is crazy about reading math recently,and he is thinking about a boring problem.

Now there are n integers Arranged in a line.For each integer,he wants to know the maximum integer in its left which is less than it.

Description

The input consists of multiple test cases.

For each case,the first line contains one integer n(0<n<=100000),indicating the number of integers.

The second line contains n integers,indicating the integers from left to right,marked a1…an.(0<ai<=10^9).

Input

For each case,there are n integers,indicating the maximum integer in ai's left which is less than it.If it doesn's exist,output -1.

Output
1
2
3
4
5
1 2 3 4 5
5
5 4 3 2 1
Sample Input
1
2
-1 1 2 3 4
-1 -1 -1 -1 -1
Sample Output
  1. 由于OJ上传数据的BUG,换行请使用"\r\n",非常抱歉
  2.  
  3. 题目大意:给你一排数字,在这个状态下,在当前数的左边找比它小的最大数字,没有就是-1
  4.  
  5. 思路:这个题说白了就是一个容器set的用法(当然其他方法也可以),这个头文件类有点多
    给个知识链接:http://www.cnblogs.com/zyxStar/p/4542835.html代码如下
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4. int n, x[];
  5. int main(){
  6. while (cin >> n){
  7. set<int>mpt;
  8. set<int>::iterator it;
  9. int i, k;
  10. for (i = ; i < n; i++){
  11. cin >> x[i];
  12. k = x[i];
  13. it = mpt.lower_bound(x[i]);
  14. if (it == mpt.begin()) x[i] = -;
  15. else{
  16. it--;
  17. x[i] = *it;
  18. }
  19. mpt.insert(k);
  20. }
  21. for (i = ; i < n; i++){
  22. if (i) cout << ' ';
  23. cout << x[i];
  24. }
  25. cout << "\r\n";
  26. }
  27. return ;
  28. }

有时候巧用容器也是不错的~~~

[Swust OJ 1026]--Egg pain's hzf的更多相关文章

  1. [Swust OJ 404]--最小代价树(动态规划)

    题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535   Des ...

  2. [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)

    题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...

  3. SWUST OJ NBA Finals(0649)

    NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128   Descri ...

  4. [Swust OJ 1023]--Escape(带点其他状态的BFS)

    解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535     Descript ...

  5. [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)

    题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  6. [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)

    题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...

  7. [Swust OJ 1139]--Coin-row problem

    题目链接:  http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...

  8. [Swust OJ 385]--自动写诗

    题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535    Descripti ...

  9. [Swust OJ 403]--集合删数

    题目链接:http://acm.swust.edu.cn/problem/403/ Time limit(ms): 5000 Memory limit(kb): 65535   Description ...

随机推荐

  1. XCode里遇到 #include <XXX.h>file not found的解决方案

    最近在学习如何在C++里调用Java方法,遇到提示 #include <XXX.h> file  not  found 的问题.也google了好久都没有找到合适的解决方案. 认真的研究了 ...

  2. Symfony框架系列----1.入门安装

    一.安装    (1)Composer安装(可选) $ curl -s https://getcomposer.org/installer | php $ php composer.phar crea ...

  3. mybatis一对一关联表查询

    先创建一个表 CREATE TABLE teacher( t_id INT PRIMARY KEY AUTO_INCREMENT, t_name ) ); CREATE TABLE class( c_ ...

  4. 【转】使用Boost Graph library(一)

    转自:http://shanzhizi.blog.51cto.com/5066308/942970 本文是一篇译文,来自:http://blog.csdn.net/jjqtony/article/de ...

  5. MFC消息截获之pretranslatemessage

    前几天,查了一个batch的问题,问题大致是这样,父窗口消息一个鼠标消息,弹出一个模态框,CPU负荷就飚升到100%(双核就是50%),非常怪异,用windbg,分析哪个线程占用CPU,定位到鼠标响应 ...

  6. 字符串模式匹配KMP算法

    一篇不错的博客:http://www.cnblogs.com/dolphin0520/archive/2011/08/24/2151846.html KMP字符串模式匹配通俗点说就是一种在一个字符串中 ...

  7. vs2013 linq to mysql

    安装文件 1.下载安装文件 2.创建项目 3.创建mysql数据连接 4.新建ADO.NET数据模型 项目实现代码 using (WorkerContainer db = new WorkerCont ...

  8. Learn Python The Hard Way, 2nd Edition 尾声

    看完了这本书,你决定继续做编程.也许它能成为你的一个职业,也许它能成为你的一项爱好.但你需要一些指导,确保自己不会走错了道路,或帮助你从这个新业余爱好中得到最大的乐趣. 我做了很久的编程.久的你都想象 ...

  9. BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )

    tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...

  10. 关于RMAN的配置信息存储和控制文件的关系

    没有使用catalog时,rman中的所有配置信息都会记入在 控制文件中 控制文件中dump出来的信息: *********************************************** ...