Unique Encryption Keys 暴力学习map,vector 函数
2012-08-29 11:44
417 查看
http://acm.hnu.cn/online/?action=problem&type=show&id=12484&courseid=0
Unique Encryption Keys |
Time Limit: 30000ms, Special Time Limit:75000ms, Memory Limit:65536KB |
Total submit users: 19, Accepted users: 15 |
Problem 12484 : Special judge |
Problem description |
The security of many ciphers strongly depends on the fact that the keys are unique and never re-used. This may be vitally important, since a relatively strong cipher may be broken if the same key is used to encrypt several different messages. In this problem, we will try to detect repeating (duplicate) usage of keys. Given a sequence of keys used to encrypt messages, your task is to determine what keys have been used repeatedly in some specified period. |
Input |
The input contains several cipher descriptions. Each description starts with one line containing two integer numbers M and Q separated by a space. M (1≤M≤1000000) is the number of encrypted messages, Q is the number of queries (0≤Q≤1000000). Each of the following M lines contains one number Ki (0≤i≤230) specifying the identifier of a key used to encrypt the i-th message. The next Q lines then contain one query each. Each query is specified by two integer numbers Bj and Ej, 1≤Bj≤Ej≤M, giving the interval of messages we want to check. There is one empty line after each description. The input is terminated by a line containing two zeros in place of the numbers M and Q. |
Output |
For each query, print one line of output. The line should contain the string ``OK" if all keys used to encrypt messages between Bj and Ej (inclusive) are mutually different (that means, they have different identifiers). If some of the keys have been used repeatedly, print one identifier of anysuch key. Print one empty line after each cipher description. |
Sample Input |
10 5 3 2 3 4 9 7 3 8 4 1 1 3 2 6 4 10 3 7 2 6 5 2 1 2 3 1 2 2 4 1 5 0 0 |
Sample Output |
3 OK 4 3 OK OK 1 |
Problem Source |
Central Europe 2011 Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,后边我们会见识到有序的好处。 /article/5063336.html c++map的使用方法 |
#include <iostream> #include <map> #include <vector> using namespace std; int min(int a,int b) { return a<b?a:b; } int main() { int m,q; int i; int x,y; while(scanf("%d%d",&m,&q)==2&&(m+q)) { vector<int > a(m); for(i=0;i<m;i++) scanf("%d",&a[i]); map<int ,int > key; //定义map 函数记录key vector<int > last(m); //last数组 记录从当前点最近一个match的点的位置 for(i=m-1;i>=0;i--) { last[i]=m; //最后一个点初始化为m if(i<m-1) last[i]=last[i+1]; //当前点初始化为当前的前一位置的最近match点 if(key.count(a[i])) last[i]=min(last[i],key[a[i]]); //如果当前点已经出现过,则选择当前点最近match点与当前点已经出现点中较小的 key[a[i]]=i; } for(i=0;i<q;i++) { scanf("%d%d",&x,&y); x--;y--; if(last[x]<=y) printf("%d\n",a[last[x]]); else printf("OK\n"); } printf("\n"); } return 0; } 学会用map,以及vector等stl模板函数 /article/4798555.html http://www.cnblogs.com/ffhajbq/archive/2012/07/16/2592926.html |
相关文章推荐
- [C++学习笔记14]动态创建对象(定义静态方法实现在map查找具体类名对应的创建函数,并返回函数指针,map真是一个万能类)good
- vector 、map 、iterator 之学习笔记
- 注意vector, list, set, map成员函数erase
- C++ Standard Stl -- SGI STL源码学习笔记(07) stl_vector 与 一些问题的细化 3 resize函数剖析
- Python学习 Day 5 高阶函数 map/reduce filter sorter 返回函数 匿名函数 装饰器 偏函数
- vector和map的erase()函数
- 使用boost的xxx_list_of函数为静态容器map和vector等赋初值
- C++STL(vector,map,set,list)成员函数整理
- C++学习笔记(字符串string、vector_deque、queue,multiset、map、multimap、容器拷贝问题)(复制粘贴,方便后面翻阅)
- spark中flatMap函数用法--spark学习(基础)
- Python小白学习之路(十五)—【map()函数】【filter()函数】【reduce()函数】
- list map vector set 常用函数列表
- python学习之函数replace capitalize split zip map
- vector与map的erase()函数详细解析
- JS学习笔记1——不要使用JavaScript内置的parseInt()和Number()函数,利用map和reduce操作实现一个string2int()函数
- map方法学习,封装函数--实现Array.prototype.map()的功能
- 大家注意vector, list, set, map成员函数erase
- perl map函数学习
- thinkphp函数学习(1)——header, get_magic_quotes_gpc, array_map, stripslashes, stripslashes_deep
- python学习——Python3.x版本中filter(),map()函数的变化