zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    WPF and SL RadioButtonList Tip
    Prism V2之旅(1)
    wpf开发常见问题(1)
    (转)英语学习者的十句经典名言
    json格式化,统一格式?,前端与后端的矛盾
    路由器默认地址跟帐号密码
    ASP操作XML数据小结
    系统封装工具和常用软件下载(2009年10月更新的)
    全国邮编、区号数据、IP数据库
    Linux 包管理速查表
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9614183.html
Copyright © 2011-2022 走看看