STL UVA 11991 Easy Problem from Rujia Liu?
题意:训练指南P187
分析:用vector存id下标,可以用map,也可以离散化用数组存(发现不用离散化也可以)
map
#include <bits/stdc++.h>
using namespace std; map<int, vector<int> >mp; int main(void) {
int n, m;
while (scanf ("%d%d", &n, &m) == 2) {
mp.clear ();
for (int a, i=1; i<=n; ++i) {
scanf ("%d", &a);
if (!mp.count (a)) mp[a] = vector<int> ();
mp[a].push_back (i);
}
while (m--) {
int k, v; scanf ("%d%d", &k, &v);
if (!mp.count (v) || mp[v].size () < k) puts ("0");
else printf ("%d\n", mp[v][k-1]);
}
} return 0;
}
离散化
#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
vector<int> vec[N];
int a[N], A[N]; int main(void) {
int n, m;
while (scanf ("%d%d", &n, &m) == 2) {
for (int i=1; i<=n; ++i) vec[i].clear ();
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]); A[i] = a[i];
}
sort (A+1, A+1+n);
int nn = unique (A+1, A+1+n) - A - 1;
for (int i=1; i<=n; ++i) {
a[i] = lower_bound (A+1, A+1+nn, a[i]) - A;
}
for (int i=1; i<=n; ++i) {
vec[a[i]].push_back (i);
}
for (int k, v, i=1; i<=m; ++i) {
scanf ("%d%d", &k, &v);
v = lower_bound (A+1, A+1+nn, v) - A;
if (vec[v].size () < k) puts ("0");
else printf ("%d\n", vec[v][k-1]);
}
} return 0;
}
STL UVA 11991 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 ...
- [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练习,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】
题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142">https://uv ...
- uva 11991 Easy Problem from Rujia Liu? vector+map
水题 学习一下数据的存储方法. #include<iostream> #include<cstdio> #include<cstdlib> #include< ...
- 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?(sort+二分 map+vector vector)
11991 - Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for e ...
随机推荐
- 使用BAT安装 Windows Service
脚本如下: @echo off @setlocal enableextensions @cd /d "%~dp0" set InstallPath=C:\DBoxService\S ...
- [Android Pro] Test win
http://www.cnblogs.com/mayingbao/ http://www.cnblogs.com/hyddd/
- Jmeter 函数
一._csvRead 函数 _cvsRead函数是从外部读取参数,csvRead函数可以从一个文件中读取多个参数. 步骤: 1.先新建一个文件,例如c.txt,里面的数据存放为 web@qq.com, ...
- 数据库支持emoji表情
从MySQL5.5.3开始,MySQL 支持一种utf8mb4的字符集,这个字符集能够支持4字节的UTF8编码的字符.utf8mb4字符集能够完美地兼容utf8字符串.在数据存储方面,当一个普通中文字 ...
- 【Java环境变量的配置问题】
首先是JVM.JRE.JDK三者之间的关系: java的跨平台性依赖于Java虚拟机:jvm(Java Virtual Machine),而jre(Java Runtime Environment,中 ...
- c++ 调用dll
1.首先写一个dll程序并且输出成dll. 新建win32项目,然后在应用程序类型中选择dll. HelloDll.h: #pragma once #ifndef MYDLL_API_EXPORTS ...
- Oracle里SID、SERVICE_NAME
本文仅用作备忘,无实际指导意义,逻辑略混乱. 1.命令show parameter name; SQL> show parameter name; NAME TYPE VALUE ------- ...
- 攻城狮在路上(壹) Hibernate(八)--- 映射Hibernate组成关系
一.使用组成关系的原则: 在不导致数据冗余的前提下,尽可能减少数据库表的数目及表之间的外键参照关系,因为建立多个表的连接是很耗时的操作. 举例说明:Customer类中的Address属性,可以通过组 ...
- TensorFlow
转自:http://blog.csdn.net/stdcoutzyx/article/details/51645396 本片博文是参考文献[1]的阅读笔记,特此声明 TensorFlow,以下简称TF ...
- PMP 第十章 项目沟通管理
1识别干系人 2规划沟通 3发布信息 4管理干系人期望 5报告绩效 1.沟通的维度有哪些?沟通技巧有哪些? 2.规划沟通管理的目的是什么?沟通渠道的计算(重点).影响沟通技术的因素有哪些?沟通模型的步 ...