zoukankan      html  css  js  c++  java
  • [Swust OJ 1026]--Egg pain's hzf

     
     
     
    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
    由于OJ上传数据的BUG,换行请使用"
    ",非常抱歉

    题目大意:给你一排数字,在这个状态下,在当前数的左边找比它小的最大数字,没有就是-1

    思路:这个题说白了就是一个容器set的用法(当然其他方法也可以),这个头文件类有点多
    给个知识链接:http://www.cnblogs.com/zyxStar/p/4542835.html代码如下
     1 #include <iostream>
     2 #include <set>
     3 using namespace std;
     4 int n, x[100001];
     5 int main(){
     6     while (cin >> n){
     7         set<int>mpt;
     8         set<int>::iterator it;
     9         int i, k;
    10         for (i = 0; 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] = -1;
    15             else{
    16                 it--;
    17                 x[i] = *it;
    18             }
    19             mpt.insert(k);
    20         }
    21         for (i = 0; i < n; i++){
    22             if (i) cout << ' ';
    23             cout << x[i];
    24         }
    25         cout << "
    ";
    26     }
    27     return 0;
    28 }
    View Code

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

  • 相关阅读:
    VMware虚拟机的三种连接方式
    Codeblocks16.01配置wxWidgets3.0.4
    DAO编程(VC6.0中的应用)
    VC++ 中用ado连接数据库
    C中文件的输入输出与C++的文件流
    Cpp中流继承关系
    a标签置灰不可点击
    手动操作数据库
    $.ajaxFileUpload is not a function
    【工具】手机号码、电话号码正则表达式
  • 原文地址:https://www.cnblogs.com/zyxStar/p/4542800.html
Copyright © 2011-2022 走看看