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

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

  • 相关阅读:
    MVC3 中上传大文件
    js 将十进制转换为八位二进制数组
    nodejs 读取并处理二进制文件
    freeswitch源码编译 ./configure 遇到的问题
    通道设置静态坐席
    呼叫中心静态座席的配置
    ECharts报表
    combotree
    openlayer PanZoom
    为什么要始终使用PreparedStatement代替Statement?
  • 原文地址:https://www.cnblogs.com/zyxStar/p/4542800.html
Copyright © 2011-2022 走看看