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 ...
随机推荐
- jQuery与JS的区别,以及jQuery的基础语法
*在使用jQuery时,要在页面最上端加上 <script src="../jquery-1.11.2.min.js"></script> 看一下js与jQ ...
- Android Studio新建了一个项目看不到手机界面的效果
我今天新建了一个项目,但是在这里却看不到手机的界面效果,如下图:
- [Android Pro] Android libdvm.so 与 libart.so
reference to :http://blog.csdn.net/koffuxu/article/details/44780351 Android libdvm.so 与 libart.so ...
- !struct operator reload
struct t3DObject //对象信息结构体{ int numOfVerts; // 模型中顶点的数目 int numOfFaces; // 模型中面的数目 int numTexVertex; ...
- C --gettimeofday===获取某个程序经历的时间
#include <stdio.h> #include <sys/time.h> #include <time.h> int gettimeofday(struct ...
- Java使用JDBC连接MySQL数据库
1.引用 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写 ...
- Jpinyin笔记
- UVA 10252
按照字典序输出最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include< ...
- 同一内网不能网段ping 不通
[root@NB sysconfig]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use ...
- C#的LINQ to Object
using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...