• ACM-ICPC 2018 I. Characters with Hash


     I. Characters with Hash

    Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encrypted value. For instance, he calls Kimura KMR, and calls Suzuki YJSNPI. One day he read a book about SHA-256256 , which can transit a string into just 256256 bits. Mur thought that is really cool, and he came up with a new algorithm to do the similar work. The algorithm works this way: first we choose a single letter L as the seed, and for the input(you can regard the input as a string ss, s[i]s[i] represents the iith character in the string) we calculates the value(|(int) L - s[i]|∣(int)L−s[i]∣), and write down the number(keeping leading zero. The length of each answer equals to 22 because the string only contains letters and numbers). Numbers writes from left to right, finally transfer all digits into a single integer(without leading zero(ss)). For instance, if we choose 'z' as the seed, the string "oMl" becomes "1111 4545 1414".

    It's easy to find out that the algorithm cannot transfer any input string into the same length. Though in despair, Mur still wants to know the length of the answer the algorithm produces. Due to the silliness of Mur, he can even not figure out this, so you are assigned with the work to calculate the answer.

    Input

    First line a integer TT , the number of test cases (T le 10)(T≤10).

    For each test case:

    First line contains a integer NN and a character zz, (N le 1000000)(N≤1000000).

    Second line contains a string with length NN . Problem makes sure that all characters referred in the problem are only letters.

    Output

    A single number which gives the answer.

    样例输入 复制
    2
    3 z
    oMl
    6 Y
    YJSNPI
    样例输出 复制
    6
    10

     1 #include <map>
     2 #include <set>
     3 #include <queue>
     4 #include <cmath>
     5 #include <stack>
     6 #include <vector>
     7 #include <string>
     8 #include <cstdio>
     9 #include <cstring>
    10 #include <climits>
    11 #include <iostream>
    12 #include <algorithm>
    13 #define wzf ((1 + sqrt(5.0)) / 2.0)
    14 #define INF 0x3f3f3f3f
    15 #define LL long long
    16 using namespace std;
    17 
    18 const int MAXN = 1e6 + 10;
    19 
    20 int t, N;
    21 char z;
    22 char temp[MAXN];
    23 
    24 int main()
    25 {
    26 //    freopen("Date1.txt", "r", stdin);
    27     scanf("%d", &t);
    28     while (t --)
    29     {
    30         int i;
    31         scanf("%d %c", &N, &z);
    32         scanf("%s", &temp);
    33         bool first = false;
    34         for (i = 0; i < N; ++ i)
    35         {
    36             if (z == temp[i]) continue;
    37             int tt = abs(int(z - temp[i]));
    38             if (tt <= 9)
    39                 first = true;
    40             break;
    41         }
    42 
    43         if (!first && i == N)
    44         {
    45             printf("1
    ");
    46             continue;
    47         }
    48 
    49         if (first)
    50             printf("%d
    ", ((N - i) << 1) - 1);
    51         else
    52             printf("%d
    ", (N - i) << 1);
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    image绑定bitmap( Binding Image.Source from download memory)
    c# 调用控制台程序并传参 获取控制台输出(解释器的前台处理)
    varchar和Nvarchar区别
    Response.Redirect:无法在发送 HTTP 标头之后进行重定向
    href="#"与href="javascript:void(0)"的区别
    CSS样式表的优先级别
    若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet
    Jquery下Json数据的传递与解析(asp.net mvc与asp.net api下后台json接收方式的不同)
    knockout.js: Uncaught Error: No Modification Allowed Err
    timepicker, datepicker ,datetimepicker
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9614183.html
Copyright © 2020-2023  润新知