[Swust OJ 1026]--Egg pain's hzf
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.
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).
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.
|
1
2
3
4
|
5
1 2 3 4 5
5
5 4 3 2 1
|
|
1
2
|
-1 1 2 3 4
-1 -1 -1 -1 -1
|
由于OJ上传数据的BUG,换行请使用"\r\n",非常抱歉 题目大意:给你一排数字,在这个状态下,在当前数的左边找比它小的最大数字,没有就是-1 思路:这个题说白了就是一个容器set的用法(当然其他方法也可以),这个头文件类有点多
给个知识链接:http://www.cnblogs.com/zyxStar/p/4542835.html代码如下
#include <iostream>
#include <set>
using namespace std;
int n, x[];
int main(){
while (cin >> n){
set<int>mpt;
set<int>::iterator it;
int i, k;
for (i = ; i < n; i++){
cin >> x[i];
k = x[i];
it = mpt.lower_bound(x[i]);
if (it == mpt.begin()) x[i] = -;
else{
it--;
x[i] = *it;
}
mpt.insert(k);
}
for (i = ; i < n; i++){
if (i) cout << ' ';
cout << x[i];
}
cout << "\r\n";
}
return ;
}
有时候巧用容器也是不错的~~~
[Swust OJ 1026]--Egg pain's hzf的更多相关文章
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)
题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...
- SWUST OJ NBA Finals(0649)
NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128 Descri ...
- [Swust OJ 1023]--Escape(带点其他状态的BFS)
解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535 Descript ...
- [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)
题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)
题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...
- [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 ...
- [Swust OJ 385]--自动写诗
题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535 Descripti ...
- [Swust OJ 403]--集合删数
题目链接:http://acm.swust.edu.cn/problem/403/ Time limit(ms): 5000 Memory limit(kb): 65535 Description ...
随机推荐
- BZOJ 1452: [JSOI2009]Count(二维BIT)
为每一个权值开一个二维树状数组. ------------------------------------------------------------------------- #include& ...
- [置顶] 老孟 DB2 V9.7 ESE(一)产品部署 基于centOS 6.4
本文安装系统CENTOS 6.4 DB2位数64 安装中涉及目录位置各位可自行定义 生产系统为安全和性能考虑,一般将DB2实例目录.日志目录.归档日志目录.表空间目录区分开,可建立/db2home / ...
- w2wp.exe 已附加有调试器,但没有将该调试器配置为调试此未经处理的异常
一.问题描述 昨天系统联调,用到了VS2010 附件进程,把w2wp.exe 进程添加到vs2010 的调试进程中,这样其他系统访问我们系统,就可以捕获断点进行调试 但是,今天F5 调试的时候,发现直 ...
- [LeetCode]题解(python):127-Word Ladder
题目来源: https://leetcode.com/problems/word-ladder/ 题意分析: 和上一题目类似,给定一个beginWord和一个endWord,以及一个字典list.这题 ...
- win7下文件名不能定义为con(任何文件格式)
从linux传输压缩包到win7下解压缩,总是提示出错,可是在linux下解压都很正常,于是定位出错的文件,发现是con.c和con.h文件,经排查,原因如下: CON是DOS下的特殊设备名 如下由系 ...
- mybatis+postgresql平台
mybatis+postgresql平台 最近有个项目的数据库使用postgresql,使用原生态的mybatis操作数据,原生态的没什么不好,只不过国内有个tk.mybatis的工具帮 ...
- html常用标签有哪些?
html看似复杂,其实常用的标签并不多,这里总共介绍一些html的常用标签 文字处理: ①标题:<h1> to <h6> ②段落:<p>文字段落</p> ...
- Protel99se教程八:protel99se原理图设计的高级应用
在我们PCB资源网的前边的protel99se教程当中,我们给大家讲解了如何绘制一个简单的原理图,以及如何将SCH原理图转为PCB,再有就是创建SCH元件,以及如何建立protel99se封库,有了上 ...
- 导入Excel加行公式和验证
package com.sprucetec.tms.controller.fee.export; import com.sprucetec.tms.controller.base.BaseFeeExp ...
- javascript 定义类(转载)
Javascript本身并不支持面向对象,它没有访问控制符,它没有定义类的关键字class,它没有支持继承的extend或冒号,它也没有用来支持虚函数的virtual,不过,Javascript是一门 ...