【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?

时间:2021-12-19 09:01:45

UVa11991 Easy Problem from Rujia Liu?

 思路:  构造数组data,使满足data[v][k]为第k个v的下标。因为不是每一个整数都会出现因此用到map,又因为每个数出现次数不等可能相差很大,因此用到vector。

注意:对于数据的清空与判空不要忘记,而map在调用之前必须有map.count的检查。

代码:

 #include<cstdio>
#include<map>
#include<vector>
using namespace std; int main(){
int n,m;
map<int,vector<int> > table; while(scanf("%d%d",&n,&m)==) {
table.clear();
int x;
for(int i=;i<=n;i++) {
scanf("%d",&x); //
if(!table.count(x)) table[x] = vector<int>(); //map.count()的判断很重要 //vector的初始化
table[x].push_back(i);
}
int k,v;
for(int i=;i<m;i++) {
scanf("%d%d",&k,&v);
if(!table.count(v) || table[v].size()<k) printf("0\n"); //在调用map之前定要count判断
else printf("%d\n",table[v][k-]); //k-1
}
}
return ;
}

【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?的更多相关文章

  1. UVA-11991 Easy Problem from Rujia Liu&quest;

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  2. uva--11991 - Easy Problem from Rujia Liu&quest;(sort&plus;二分 map&plus;vector vector)

    11991 - Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for e ...

  3. uva11991 Easy Problem from Rujia Liu&quest;

    Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an ...

  4. 11991 - Easy Problem from Rujia Liu&quest;(的基础数据结构&rpar;

    UVA 11991 - Easy Problem from Rujia Liu? 题目链接 题意:给一个长度n的序列,有m询问,每一个询问会问第k个出现的数字的下标是多少 思路:用map和vector ...

  5. UVa 11991&colon;Easy Problem from Rujia Liu&quest;(STL练习,map&plus;vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  6. UVA 11991 Easy Problem from Rujia Liu&quest;(vector map)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  7. &lbrack;UVA&rsqb; 11991 - Easy Problem from Rujia Liu&quest; &lbrack;STL应用&rsqb;

    11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...

  8. uva 11991 - Easy Problem from Rujia Liu&quest;&lpar;STL&rpar;

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142" target="_blank ...

  9. CJOJ 2485 UVa 11991 生日礼物 &sol; UVa 11991 Easy Problem from Rujia Liu&quest;

    CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu? Description (原题来自刘汝佳<训练指南>Pa ...

随机推荐

  1. Zygote进程【3】——SystemServer的诞生

    在ZygoteInit的main()方法中做了几件大事,其中一件便是启动Systemserver进程,代码如下: @/frameworks/base/core/Java/com/Android/int ...

  2. ci控制器写规范

    不需要后缀名 文件名全部小写 所有控制器需要直接或者间接继承CI_Controller 以下划线开头的方法为私有方法,不能被请求 protected private的方法不能被浏览器请求 ci方法名不 ...

  3. powerdesigner连接数据库 导出数据 生成PDM文件 傻瓜试教程

    也可下载文档:http://download.csdn.net/detail/shutingwang/6378665 

  4. javascript第六课类型转换

    1.parseint(参数): 转换为整数,即使参数中的字符串包含字母数字混合,此方法也会自动一个一个判断和转换   parseInt(参数,进制);将参数通过几进制的方式转为数字 2.parsefl ...

  5. &dollar;in的方法总结

    Ad.find({"_id":{$in:datas}},function(err,item){ if(err) console.log(err); //console.log(it ...

  6. android 之 java环境部署

    上甲骨文公司官网下载最新的jdk http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-z ...

  7. 2017-3-10 SQL server 数据库 T--SQL语句

    创建数据库:create datebase  数据库名     注:数据库名不能为中文,不能数字开头,不能符号开头. 删除数据库:drop datebase 数据库名 创建表:create   tab ...

  8. ubuntu下使用 chkconfig 是一种习惯

    ubuntu下使用 chkconfig 是一种习惯 习惯了chkconfig命令, 闲来写了个脚本模拟下, 步骤很简单. 如下: 第一步, 安装sysv-rc-conf sudo apt instal ...

  9. 从&period;Net到Java学习第四篇——spring boot&plus;redis

    从.Net到Java学习系列目录 “学习java已经十天,有时也怀念当初.net的经典,让这语言将你我相连,怀念你......”接上一篇,本篇使用到的框架redis.FastJSON. 环境准备 安装 ...

  10. bank&lowbar;card&period;js

    function init() { undefined = "undefined"; mkCClist(); } function ccchk(cdi) { output1 = & ...