[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 ...
随机推荐
- SQL中 and or优先级问题
资源来源:http://www.linuxidc.com/Linux/2012-03/56267.htm 刚刚在项目中遇到这样一个问题,SQL语句如下: select * from LOAN_BACK ...
- 什么是RAW?
RAWRAW是一个PHP网站开发系统,使用简单.快捷,核心功能是通过模版组合网站,模版可以自由开发,使开发者不再受传统开发的那种头晕限制,只需要通过填写表单即可完成网站的开发.此外,开发者还可以通过开 ...
- shell学习-读取输入
功能:读取输入,打印:如果长度小于MINLEN,那么输出空格. #!/bin/bash # paragraph-space.sh # Insert a blank line between parag ...
- Cubieboard 关闭板载led
修改script.bin 找到最后节点[led_para] 修改leds_used = 0 script.bin 一般在系统盘的第一个分区 例如nand就在/dev/nanda sdcard就在/d ...
- ElasticSearch 插件配置
http://blog.sina.com.cn/s/blog_8f31e5b10101dsnq.html http://www.tuicool.com/articles/mMZfu2 http://b ...
- S50卡
产品名称:Mifare 1K(S50)卡 芯片类型:Philips Mifare 1 IC S50 存储容量:8Kbit,16个分区,每分区两组密码 工作频率:13.56 MHz 通讯速率:106KB ...
- 从51跳cortex-m0学习2——程序详解
跳cortex-m0——思想转变>之后又一入门级文章,在此不敢请老鸟们过目.不过要是老鸟们低头瞅了一眼,发现错误,还请教育之,那更是感激不尽.与Cortex在某些操作方式上的异同,让自己对Cor ...
- CI 模板解析器类
模板解析器类可以解析你的视图文件中的伪变量.它可以解析简单的变量或者以变量作为标签的结构.如果你以前没有用过模板引擎,那么伪变量如下所示: <html><head><ti ...
- <Win32_16>来看看标准菜单和右键菜单的玩法
日常应用中,菜单主要分为两种:(1) 标准菜单(处于应用程序菜单栏处的菜单) (2)右键快捷菜单 几乎你所见过或使用过的软件中,都有它俩儿 为应用程序添加它们的基本步骤: (1)用代码或者IDE ...
- javasrcipt日期一些方法和格式转化
Js获取当前日期时间及其它操作 var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); ...