[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 ...
随机推荐
- Elasticsearch 单模式下API的增删改查操作
<pre name="code" class="html">Elasticsearch 单模式下API的增删改查操作 http://192.168. ...
- 可以放在html代码中的自动跳转代码
可以放在html代码中的自动跳转代码 有3种方法可以实现html的页面跳转,1,refresh 2,onload事件中加入代码 3,js实现 1.<html><body> ...
- HDU 2852 KiKi's K-Number
权值线段树 #include <cstdio> #include <cstring> const int N=200000,M=220000; int k,q,x,y,sum[ ...
- 在cnblog中使用syntax方法
<pre name="code" class="brush: cpp;"> 代码 </pre> #include<cstdio&g ...
- 用git上传项目到github
1 git clone github仓库地址 2 git add . 3 git commit -m "changes log" 4 git remote add origi ...
- 数据结构与算法分析 3.4&3.5 — 链表的交与并算法
代码: #include <list> template<typename ElementType> list<ElementType> Intersect(con ...
- express文件上传
安装express,创建项目,添加sqlite3模块 express --sessions --css stylus --ejs myhotel npm install sqlite3node app ...
- JavaScript推断E-mail地址是否合法
编写自己定义的JavaScript函数checkEmail(),在该函数中首先推断E-mail文本框是否为空,然后在应用正則表達式推断E-mail地址是否合法,假设不合法提示用户 <script ...
- 信号量多-threaded同步Semaphore
Semaphore它是JDK1.5一个实现后,外面有个办法同步.Semaphore能够保持其当前的线程接入号码.并提供了一个同步机制. 采用Semaphore时,可以用相同的对资源的访问进行控制的线程 ...
- 使用LINQ的几个小技巧
这里总结了这些技巧.介绍如何使用LINQ来: 初始化数组 在一个循环中遍历多个数组 生成随机序列 生成字符串 转换序列或集合 把值转换为长度为1的序列 遍历序列的所有子集 如果你在LINQ方面有心得也 ...