《算法竞赛-训练指南》第三章-2.2_UVa 11991
来源:互联网 发布:9080端口 编辑:程序博客网 时间:2024/05/16 19:24
这道题目也是比较简单的吧,就是用vector就可以解决,也是一个比较简单的用vector,当做邻接表来用吧。比较方便,实用。
这个没有什么好说的,就是注意每次用完之后都要清楚一遍容器就行了。
贴出代码:
#include <stdio.h>#include <string.h>#include <vector>#include <iostream>#include <string>using namespace std;const int MAXN = 1000000 + 11;int N, M;vector <int> V[MAXN];void init(){for (int i = 0; i < N; i++){V[i].clear();}}int main(){int a;while (scanf("%d%d", &N, &M) != EOF){init();for (int i = 1; i <= N; i++){scanf("%d", &a);V[a].push_back(i);}int k, v;for (int i = 0; i < M; i++){scanf("%d%d", &v, &k);int nc = V[k].size();if (nc < v){printf("0\n");}else{printf("%d\n", V[k][v - 1]);}}}//system("pause");return 0;}
- 《算法竞赛-训练指南》第三章-2.2_UVa 11991
- 《算法竞赛-训练指南》第三章-3.8_UVa 11235
- 《算法竞赛-训练指南》第二章-2.2_UVa 11401
- 《算法竞赛-训练指南》第三章-3.1_UVa 11995(STL数据结构运用)
- 《算法竞赛-训练指南》第二章-2.1_UVa 11538
- 《算法竞赛-训练指南》第二章-2.3_UVa 11806
- 《算法竞赛-训练指南》第二章-2.5_UVa 11361
- 《算法竞赛-训练指南》第二章-2.9_UVa 11426
- 《算法竞赛-训练指南》第二章-2.14_UVa 11021
- 《算法竞赛-训练指南》第二章-2.15_UVa 11722
- 《算法竞赛-训练指南》-第二章-2.16_UVa 11427
- 《算法竞赛-训练指南》-第二章-2.18_UVa 10294
- 《算法竞赛-训练指南》第二章-2.26_UVa 10341
- 《算法竞赛-训练指南》第五章-5.1_UVa 11624
- 《算法竞赛-训练指南》第五章-5.2_UVa 10047
- 《算法竞赛-训练指南》第一章-1.5_UVa 10881
- 《算法竞赛-训练指南》-第一章-1.10_UVa 11384
- 《算法竞赛-训练指南》第一章-1.17_UVa 11462
- C语言编程杂记
- UVA 10635 Prince and Princess 最长公共子序列
- 多线程并发实践_笔记_第七章
- Chapter3 Exercises3.3 E7
- cannot be cast to javax.servlet.Filter 报错, 原因servlet-api.jar冲突
- 《算法竞赛-训练指南》第三章-2.2_UVa 11991
- Error parsing XPath '/sqlMapConfig/sqlMap'
- Android + kernel USB host 如何判断插入的设备是高速还是低速的设备
- UVALive 3363 String Compression (区间DP,4级)
- 见表空间授权
- iOS - Actions and Outlet
- ltib(2)小试
- C++输出IP地址段内的合法地址
- 经典领悟