K-th Number(第k大数)
Time Limit: 20000MS | Memory Limit: 65536K | |
Total Submissions: 45710 | Accepted: 15199 | |
Case Time Limit: 2000MS |
Description
Input
Output
Sample Input
7 3
1 5 2 6 3 7 4
2 5 3
4 4 1
1 7 3
Sample Output
5
6
3
Hint
extern "C++"{
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL;
void SI(int &x){scanf("%d",&x);}
void SI(double &x){scanf("%lf",&x);}
void SI(char *x){scanf("%s",x);}
//void SI(LL &x){scanf("%lld",&x);} void PI(int &x){printf("%d",x);}
void PI(double &x){printf("%lf",x);}
void PI(char *x){printf("%s",x);}
//void PI(LL &x){printf("%lld",x);} }
const int MAXN = ;
struct Node{
int id,v;
bool operator < (const Node &b)const{
return v < b.v;
}
};
Node dt[MAXN];
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i = ;i <= n;i++){
SI(dt[i].v);
dt[i].id = i;
}
sort(dt + ,dt + n + );
//for(int i = 1;i <= n;i++)printf("%d ",dt[i].v);puts("");
int l,r,t;
while(m--){
scanf("%d%d%d",&l,&r,&t);
for(int i = ;i <= n;i++){
if(dt[i].id >= l && dt[i].id <= r){
t--;
if(t == ){
printf("%d\n",dt[i].v);break;
}
}
}
}
}
return ;
}
package com.lanqiao.week1; import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner; public class poj2104 {
private static Scanner cin;
private static int MOD = 1000000007;
static{
cin = new Scanner(System.in);
}
private static class Node{
int i, v;
}
public static void main(String[] args) {
int n, m;
n = cin.nextInt();
m = cin.nextInt();
Node[] arr = new Node[n];
for(int i = 0; i < n; i++){
arr[i] = new Node();
arr[i].i = i + 1;
arr[i].v = cin.nextInt();
}
Arrays.sort(arr, new Comparator<Node>() { @Override
public int compare(Node a, Node b) {
if(a.v != b.v){
return a.v - b.v;
}else{
return a.i - b.i;
}
} });
while(m-- > 0){
int s, e, k;
s = cin.nextInt();
e = cin.nextInt();
k = cin.nextInt();
int cnt = 0;
for(int i = 0; i < n ; i++){
if(arr[i].i >= s && arr[i].i <= e){
cnt ++;
if(cnt == k){
System.out.println(arr[i].v);
break;
}
}
}
}
} }
K-th Number(第k大数)的更多相关文章
- [Swift]LeetCode995. K 连续位的最小翻转次数 | Minimum Number of K Consecutive Bit Flips
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray o ...
- 题目1040:Prime Number(第k个素数)
题目链接:http://ac.jobdu.com/problem.php?pid=1040 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- [LeetCode] Minimum Number of K Consecutive Bit Flips 连续K位翻转的最小次数
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray o ...
- 51 Nod 1116 K进制下的大数
1116 K进制下的大数 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 有一个字符串S,记录了一个大数,但不知这个大数是多少进制的,只知道这个数 ...
- 【leetcode】995. Minimum Number of K Consecutive Bit Flips
题目如下: In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) suba ...
- [51nod1116]K进制下的大数
解题关键:$A\% (k - 1) = (A[0] + A[1]*k + A[2]*{k^2} + ...A[n]*{k^n})\% (k - 1) = (A[0] + A[1] + ...A[n]) ...
- 快速排序/快速查找(第k个, 前k个问题)
//快速排序:Partition分割函数,三数中值分割 bool g_bInvalidInput = false; int median3(int* data, int start, int end) ...
- [LeetCode] Top K Frequent Words 前K个高频词
Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted b ...
- [CareerCup] 13.1 Print Last K Lines 打印最后K行
13.1 Write a method to print the last K lines of an input file using C++. 这道题让我们用C++来打印一个输入文本的最后K行,最 ...
- 一些简单的问题. 2的10次方与k (涉及到b k m的要用乘来解读)
2的10次方是k k就表示2的10次方 2的16次方,解读为 2的6次方(64)*2的10次方(k) 简写为64k 64k=64*k 同理2的20次方 解读为2的10次方*2的10次方 k ...
随机推荐
- PHP MySQL Select 之Select
从数据库表中选取数据 SELECT 语句用于从数据库中选取数据. 语法 SELECT column_name(s) FROM table_name 注释:SQL 语句对大小写不敏感.SELECT 与 ...
- Android应用程序与SurfaceFlinger服务的关系概述和学习计划
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/7846923 SurfaceFlinger服务负 ...
- qt获取本机网络信息
networkinformation.h #include<QtGui/QWidget> #include<QLabel> #include<QPushButton> ...
- [裸KMP][HDU1711][Number Sequence]
题意 找到子串在母串出现的第一个位置 解法 裸的KMP 特别的地方 第一次不看模板自己敲的KMP #include<stdio.h> const int maxn=100000; cons ...
- Table生成Excel表格
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- OCMOCM
14年,OCM考试费12000 15年,考试费19800 对于我来说,1,2年之后是否换工作还是个未知数 在本单位考这个貌似没什么用处,工资也不会突然就涨很多 跳槽的话,专门做数据库感觉压力还挺大 年 ...
- jquery mobile 入门级实战1
第一步:使用CDN接入jquery mobile CDN的全称是Content Delivery Network,即内容分发网络.其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的瓶颈和环 ...
- MySQL server has gone away报错
1.最近做插入数据库,然后一直报一个错.mysql server has gone away.(如下图) 查了好多资料,终于解决了.. 1.可能是连接超时..进入php.ini,修改wait_time ...
- 小端存储(little Endian)大端存储(big Endian)
小端存储--低内存低字节 87654321 字节或半字节的最低位字节(Lowest Significant Bit,LSB)存放于内存最低位字节地址上.即最低地址存放的最低字节,为Power PC,I ...
- bzoj 2648 SJY摆棋子 kd树
题目链接 初始的时候有一些棋子, 然后给两种操作, 一种是往上面放棋子. 另一种是给出一个棋子的位置, 问你离它最近的棋子的曼哈顿距离是多少. 写了指针版本的kd树, 感觉这个版本很好理解. #inc ...