zoukankan      html  css  js  c++  java
  • Central Europe Regional Contest 2011

    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

    题意:告诉你从1-n的区间内,依次对应一个整数,询问给定一个区间,是否存在两个相同的整数。

     1 #include <cstdio>
     2 #include <set>
     3 #include <map>
     4 #include <vector>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 int n,m;
     9 vector<int> value;
    10 
    11 int main()
    12 {
    13     for(;;) 
    14     {
    15         scanf("%d %d\n", &n, &m);
    16         if (!n) return 0;
    17         value.resize(n);
    18         for (int i = 0; i < n; i++) 
    19         {
    20             scanf("%d", &value[i]);
    21         }
    22 
    23         map<int,int> last_occ;                //用于记录当前的最小匹配区间
    24         vector<int> first_match(n);           //用于记录从i位置之后最先匹配的区间的右侧
    25         for (int i = n-1; i >= 0; i--) 
    26         {
    27             first_match[i] = n;
    28             if (i < n-1)
    29                 first_match[i] = first_match[i+1];
    30             if (last_occ.count(value[i]))
    31                 first_match[i] = min(first_match[i], last_occ[value[i]]);      //更新区间
    32             last_occ[value[i]] = i; 
    33         }
    34 
    35         for (int i = 0; i < m; i++)
    36         {
    37             int x, y;
    38             scanf("%d %d",&x, &y);
    39             x--;
    40             y--;
    41             if (first_match[x] <= y)
    42             {
    43                 printf("%d\n",value[first_match[x]]);
    44             } 
    45             else
    46             {
    47                 printf("OK\n");
    48             }
    49         }
    50         printf("\n");
    51     }
    52 }
    53 /*
    54 12 10
    55 2
    56 6
    57 12
    58 5
    59 6
    60 4
    61 7
    62 6
    63 7
    64 14
    65 2
    66 14
    67 3 7
    68 */


    题目链接:http://acm.hnu.cn/online/?action=problem&type=list&courseid=233

    注意一下vector和map的用法

    1、vector<int>value(n);                         value大小为n             等同于      vector<int>value;          value.resize(n);

    2、map<int,int>cnt;               等同于建立一个映射((int)x->(int)y)

  • 相关阅读:
    ES6-01 2018-02-06
    8.1 IO类
    2.4 const限定符
    C++命名空间
    win7系统docker安装ubuntu
    win7安装docker
    wuzhicms 查看模板中的所有可用变量和值
    wuzhicms上传弹出层,如何返回数据到当前页面?
    wuzhicms 无规律推荐位标签的嵌套使用
    【wuzhicms】apache 设置禁止访问某些文件或目录
  • 原文地址:https://www.cnblogs.com/XBWer/p/2662162.html
Copyright © 2011-2022 走看看