[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 ...
随机推荐
- Google地图,Baidu地图数据供应商
http://janwen.iteye.com/blog/488659 Google百度 我老以为百度,Google的地图产品是自己开发的,原来是别人提供的数据, 百度的数据提供商有 北京世纪高通科 ...
- jQuery常用效果
1.滑动效果 向上效果:slideUp() 向下效果:slideDown() 向上与向下切换:slideToggle() 2.淡入淡出效果 显示与隐藏切换:fadeToggle() 3.显示隐藏 显示 ...
- php学习笔记(3)
1.计数器 <?php /* simple access counter for php3 (c)1998 David W. Bettis dbettis@eyeintegrated.com m ...
- zoj 3195 Design the city lca倍增
题目链接 给一棵树, m个询问, 每个询问给出3个点, 求这三个点之间的最短距离. 其实就是两两之间的最短距离加起来除2. 倍增的lca模板 #include <iostream> #in ...
- java Serialization and Deserializaton
This article from JavaTuturial Java provides a mechanism, called object serialization where an objec ...
- ios如何实现推送通知
推送通知的步骤:1.询问是否允许推送通知.2.如果用户允许在APPDELEGATE 中实现 - (void)application:(UIApplication *)application didRe ...
- RatProxy
http://book.51cto.com/art/201212/374023.htm http://www.oschina.net/p/ratproxy/similar_projects
- HDU 2215 Maple trees
增量法的最小包围圈算法,不会…… #include <cstdio> #include <cstring> #include <iostream> #include ...
- 运行于64操作系统上的C#客户端通过WCF访问Oracle数据库不兼容问题
运行平台: Windows 7 64位操作系统 运行环境: IIS 7 编程语言:C# 数据库: 32位的Oracle 10g 运行原因:64位操作系统C#客户端程序通过WCF访问ORACLE数据库 ...
- HDU 1104 Remainder( BFS(广度优先搜索))
Remainder Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...