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?的更多相关文章
-
UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
-
uva--11991 - Easy Problem from Rujia Liu?(sort+二分 map+vector vector)
11991 - Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for e ...
-
uva11991 Easy Problem from Rujia Liu?
Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an ...
-
11991 - Easy Problem from Rujia Liu?(的基础数据结构)
UVA 11991 - Easy Problem from Rujia Liu? 题目链接 题意:给一个长度n的序列,有m询问,每一个询问会问第k个出现的数字的下标是多少 思路:用map和vector ...
-
UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
-
UVA 11991 Easy Problem from Rujia Liu?(vector map)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
-
[UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]
11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...
-
uva 11991 - Easy Problem from Rujia Liu?(STL)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142" target="_blank ...
-
CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu?
CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu? Description (原题来自刘汝佳<训练指南>Pa ...
随机推荐
-
Zygote进程【3】——SystemServer的诞生
在ZygoteInit的main()方法中做了几件大事,其中一件便是启动Systemserver进程,代码如下: @/frameworks/base/core/Java/com/Android/int ...
-
ci控制器写规范
不需要后缀名 文件名全部小写 所有控制器需要直接或者间接继承CI_Controller 以下划线开头的方法为私有方法,不能被请求 protected private的方法不能被浏览器请求 ci方法名不 ...
-
powerdesigner连接数据库 导出数据 生成PDM文件 傻瓜试教程
也可下载文档:http://download.csdn.net/detail/shutingwang/6378665
-
javascript第六课类型转换
1.parseint(参数): 转换为整数,即使参数中的字符串包含字母数字混合,此方法也会自动一个一个判断和转换 parseInt(参数,进制);将参数通过几进制的方式转为数字 2.parsefl ...
-
$in的方法总结
Ad.find({"_id":{$in:datas}},function(err,item){ if(err) console.log(err); //console.log(it ...
-
android 之 java环境部署
上甲骨文公司官网下载最新的jdk http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-z ...
-
2017-3-10 SQL server 数据库 T--SQL语句
创建数据库:create datebase 数据库名 注:数据库名不能为中文,不能数字开头,不能符号开头. 删除数据库:drop datebase 数据库名 创建表:create tab ...
-
ubuntu下使用 chkconfig 是一种习惯
ubuntu下使用 chkconfig 是一种习惯 习惯了chkconfig命令, 闲来写了个脚本模拟下, 步骤很简单. 如下: 第一步, 安装sysv-rc-conf sudo apt instal ...
-
从.Net到Java学习第四篇——spring boot+redis
从.Net到Java学习系列目录 “学习java已经十天,有时也怀念当初.net的经典,让这语言将你我相连,怀念你......”接上一篇,本篇使用到的框架redis.FastJSON. 环境准备 安装 ...
-
bank_card.js
function init() { undefined = "undefined"; mkCClist(); } function ccchk(cdi) { output1 = & ...