训练三 B

Description

The database of the Pentagon contains a top-secret information. We don‘t know what the information is — you know, it‘s top-secret, — but we know the format of its representation. It is extremely simple. We don‘t know why, but all the data is coded by the natural numbers from 1 up to 5000. The size of the main base (we‘ll denote it be N) is rather big — it may contain up to 100 000 those numbers. The database is to process quickly every query. The most often query is: "Which element is i-th by its value?"— with i being a natural number in a range from 1 to N.

Your program is to play a role of a controller of the database. In the other words, it should be able to process quickly queries like this.

input

The standard input of the problem consists of two parts. At first, a database is written, and then there‘s a sequence of queries. The format of database is very simple: in the first line there‘s a number N, in the next N lines there are numbers of the database one in each line in an arbitrary order. A sequence of queries is written simply as well: in the first line of the sequence a number of queries K (1 <= K <= 100) is written, and in the next K lines there are queries one in each line. The query "Which element is i-th by its value?" is coded by the number i. A database is separated from a sequence of queries by the string of three symbols "#".

output

The output should consist of K lines. In each line there should be an answer to the corresponding query. The answer to the query "i" is an element from the database, which is i-th by its value (in the order from the least up to the greatest element).

Sample Input

5
7
121
123
7
121
###
4
3
3
2
5Sample Output
121
121
7
123

#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int i,j,n,m;
int a[100001];
char s[5];//字符,包括‘\0‘
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
cin>>s;
cin>>m;
while(m--)
{
int j;
cin>>j;
cout<<a[j-1]<<endl;
}

return 0;
}

心得:设置数组的时候一定要设置大一点!对快排更加熟练~

时间: 2024-08-30 06:43:33

训练三 B的相关文章

训练三:求任意整数的降序数

题目要求: 对一个五位的任意整数,求出琦降序数 算法提示:将整数的每一位分离到一维整形数组中,再将数组a的元素按照降序排列,最后输出数组元素值, 试建立一个NUM类,完成上述操作 #include<iostream> using namespace std; class NUM { public: NUM(int x);//定义一个带参数的构造函数 void NUM_fengjie(); void NUM_paixu(); void NUM_display(); private: int a[

李新海:师徒聊“口才训练三阶段”

昨天和徒弟聊天,他告诉我,他总结了口才训练的三个阶段 一.看山是山,看水是水 外行看热闹,内行看门道,刚开始的时候,口才不好,看见口才好的演讲者,培训师,会很羡慕,会竖起大拇指认可那些高手. 最近特别火的<欢乐喜剧人><笑傲江湖><跨界喜剧王>三个节目来说,90%的人看了节目,哈哈大笑,但是外行始终是外行, 根本不知道对方用了什么技巧,不知道有哪些套路. 而口才演讲,培训讲课,也和这些喜剧节目类似,都是有专业的技巧的.如果不懂,那只能在原地停留. 二.看山不是山,看水不

英语听力训练三原则四个字

什么是听力训练的三原则.四个字呢.三个原则是:有恒,即持之以恒:有序,循序渐进:有量,要有一定数量的听力训练.四个字:3.6.9.什么是3?就是最好每次坚持进行至少30分钟的听力练习.6呢,一个星期,即进行至少6次的听力训练.9是一个层次的听力练习,至少要听够90篇以上的数量,如果条件许可,还可以在此基础上加大训练量.     “有恒”的道理,就不用说了.任何学问的取得,都离不开这个道理.没有恒心,想成就一番事业是不可能的.其实,我们国家很多学英语的人何其多也,但真正学成的,比例很有限,为什么呢

022.强化训练三

函数的返回值都在EAX中.64位返回值. 当我们写Windows32位C语言程序的时候.使用参数和局部变量,能用int,就别用short和char类型.涉及到一个程序内存对齐. 参数和局部变量没有本质的区别,都是在函数被调用的时候,在栈中分配的.甚至完全可以把参数当做局部变量使用. 参数是在函数调用前分配的内存.call之前.局部变量是函数调用时分配的内存.call中. 但是call之后,它们就全从栈中被排除之外了. int x= 10;int y =x+10;int z =x*y;int x

基于协同训练的半监督文本分类算法

标签: 半监督学习,文本分类 作者:炼己者 --- 本博客所有内容以学习.研究和分享为主,如需转载,请联系本人,标明作者和出处,并且是非商业用途,谢谢! 如果大家觉得格式看着不舒服,也欢迎大家去看我的简书 半监督学习文本分类系列 用半监督算法做文本分类(sklearn) sklearn半监督学习(sklearn) 基于自训练的半监督文本分类算法 一. 摘要 本文主要讲述基于协同训练的半监督算法做文本分类,用三个差异性比较大的分类器对未标注数据进行标注,它们可以进行交叉验证,大大提升了对未标注数据

BERT论文翻译:用于语言理解的深度双向Transformer的预训练

Jacob Devlin Ming-Wei Chang Kenton Lee kristina Toutanova Google AI Language {jacobdevlin, mingweichang, kentonl, kristout}@google.com 摘要 本文介绍了一种新的语言表示模型BERT,意为“来自transformer的双向编码器表示”(Bidirectional Encoder Representations from Transformers).与最近的语言表示模

字符串训练之三

字符串训练三 https://www.luogu.org/problem/P4551 题目描述: 给定一棵n个点的带权树,结点下标从1开始到N.寻找树中找两个结点,求最长的异或路径. 异或路径指的是指两个结点之间唯一路径上的所有边权的异或 分析: 嗯?这不是个图论题吗?什么狗屁字符串? 首先看到异或,那01trie树就必不可少的了 首先对一条边异或2次,相当于没有异或. 这样的话 i -> j 的异或和,就是 i -> 1 的异或和,再异或上 1 -> j 的异或和. 处理出每个点到1路

【转载】GBDT(MART) 迭代决策树入门教程 | 简介

      转载地址:http://blog.csdn.net/w28971023/article/details/8240756        GBDT(Gradient Boosting Decision Tree) 又叫 MART(Multiple Additive Regression Tree),是一种迭代的决策树算法,该算法由多棵决策树组成,所有树的结论累加起来做最终答案.它在被提出之初就和SVM一起被认为是泛化能力(generalization)较强的算法.近些年更因为被用于搜索排

今天开始认真刷数学

不得不说数学是制胜的法宝,但是也确实很难,系统地针对地进行训练十分有必要: VJUDGE自行训练,发布者lvbu: ID   Title   Begin Time Length Owner 165317    [kuangbin]数学训练一 [Cloned]   5 min later 60 days lvbu 165319    [kuangbin]数学训练三 [Cloned]   5 min later 50.2 days lvbu 165318    [kuangbin]数学训练二 cou