zoukankan      html  css  js  c++  java
  • oj 小黑熊偷玉米

    Description

    小黑熊的邻居bob 家里种很多玉米,玉米被布置在一条线上 。小黑熊贪心要偷玉米。但bob家是太多了玉米,所以小黑熊决定选择时间间隔[l,r]偷。因为小黑熊的幸运号码是k,的区间里第k大的一个玉米。
    如今请你帮助小黑熊计算一下它将偷的玉米有多大吧

    Input

    第一行包括一个数n(n<=1000)。表示玉米的总个数。

    第二行包括n个正整数(每一个数不超过10的6次方),表示每一个玉米的大小。

    第三个包括一个正整数m(m<=1000)。表示询问个数。
    接下来m行,每行三个数l,r,k(k<=(r-l+1)),代表上面的所涉及的元素,表示询问序列从左往右第l个数到第r个数中,从大往小第k大的玉米是哪个。序列元素从1開始标号。

    Output

    总共输出m行,每行一个数,表示询问的答案。

    Sample Input

    5
    1 2 3 4 5
    2
    1 5 2
    2 3 2
    

    Sample Output

    4
    2
    

    HINT

    AC代码:
    #include <iostream>
    #include <cmath>
    #include <cstdio>
    #include <algorithm>
    #include <cctype>
    #include <cstdlib>
    #include <cstring>
    #define MAXN 1000
    using namespace std;
    int main(){
        int n;
        cin>>n;
        int a[n],i,m;
        i=0;
        while(i<n){
            cin>>a[i++];
        }
        cin>>m;
        int l,r,k,j,t;
        while(m){
            cin>>r>>l>>k;
            int b[l-r+1];
            for(i=r-1,j=0;i<l;j++,i++)
                b[j]=a[i];
                t=l-r+1;
            sort(b,b+l-r+1);
            cout<<b[t-k]<<'12';
            m--;
        }
        return 0;
    }
     


    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    Install wget in Mac OS X Without Homebrew or MacPorts
    Embedding Lua in C: Using Lua from inside C.
    Lua 的数据结构
    Maintainable HashCode and Equals Using Apache Commons
    Multiples of 3 and 5
    Even Fibonacci numbers
    Eclipse Error: Unable to set localhost. This prevents creation of a GUID.
    Oracle中merge into的使用
    MERGE
    pl/sql tutorial
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4883450.html
Copyright © 2011-2022 走看看