• BestCoder Round #88


    A、Find Q

    Accepts: 392
    Submissions: 780
    Time Limit: 2000/1000 MS (Java/Others)
    Memory Limit: 262144/131072 K (Java/Others)
    Problem Description
     

    Byteasar is addicted to the English letter 'q'. Now he comes across a string SSS consisting of lowercase English letters.

    He wants to find all the continous substrings of SSS, which only contain the letter 'q'. But this string is really really long, so could you please write a program to help him?

    Input

    The first line of the input contains an integer T(1≤T≤10)T(1leq Tleq10)T(1T10), denoting the number of test cases.

    In each test case, there is a string SSS, it is guaranteed that SSS only contains lowercase letters and the length of SSS is no more than 100000100000100000.

    Output

    For each test case, print a line with an integer, denoting the number of continous substrings of SSS, which only contain the letter 'q'.

    Sample Input
    2
    qoder
    quailtyqqq
    Sample Output
    1
    7
     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <algorithm>
     6 #include <cmath>
     7 #include <time.h>
     8 #include <string>
     9 #include <map>
    10 #include <stack>
    11 #include <vector>
    12 #include <set>
    13 #include <queue>
    14 #define inf 0x7fffffff
    15 #define mod 10000
    16 #define met(a,b) memset(a,b,sizeof a)
    17 typedef long long ll;
    18 using namespace std;
    19 const int N = 100;
    20 const int M = 100000;
    21 const int INF = 0x3f3f3f3f;
    22 int x;
    23 
    24 char s[100002];
    25 long long int a[1000];
    26 
    27 int main()
    28 {
    29     long long int sum = 0;
    30     int t;
    31     scanf("%d", &t);
    32     while(t--)
    33     {
    34         scanf("%s", s);
    35         int len = strlen(s);
    36         long long int cnt = 0;
    37         sum = 0;
    38         for(int i = 0; i < len; i++)
    39         {
    40             if(s[i] == 'q')
    41             {
    42                 cnt++;
    43             }else if(cnt > 0){
    44                 sum += cnt*(cnt+1)/2;
    45                 cnt = 0;
    46             }
    47         }
    48         if(cnt > 0) sum += cnt*(cnt+1)/2;
    49         printf("%lld
    ", sum);
    50     }
    51 }

    Abelian Period

    Accepts: 288
    Submissions: 984
    Time Limit: 2000/1000 MS (Java/Others)
    Memory Limit: 262144/131072 K (Java/Others)
    Problem Description

    Let SSS be a number string, and occ(S,x)occ(S,x)occ(S,x) means the times that number xxx occurs in SSS.

    i.e. S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1.

    String u,wu,wu,w are matched if for each number iii, occ(u,i)=occ(w,i)occ(u,i)=occ(w,i)occ(u,i)=occ(w,i) always holds.

    i.e. (1,2,2,1,3)≈(1,3,2,1,2)(1,2,2,1,3)approx(1,3,2,1,2)(1,2,2,1,3)(1,3,2,1,2).

    Let SSS be a string. An integer kkk is a full Abelian period of SSS if SSS can be partitioned into several continous substrings of length kkk, and all of these substrings are matched with each other.

    Now given a string SSS, please find all of the numbers kkk that kkk is a full Abelian period of SSS.

    Input

    The first line of the input contains an integer T(1≤T≤10)T(1leq Tleq10)T(1T10), denoting the number of test cases.

    In each test case, the first line of the input contains an integer n(n≤100000)n(nleq 100000)n(n100000), denoting the length of the string.

    The second line of the input contains nnn integers S1,S2,S3,...,Sn(1≤Si≤n)S_1,S_2,S_3,...,S_n(1leq S_ileq n)S1​​,S2​​,S3​​,...,Sn​​(1Si​​n), denoting the elements of the string.

    Output

    For each test case, print a line with several integers, denoting all of the number kkk. You should print them in increasing order.

    Sample Input
    2
    6
    5 4 4 4 5 4
    8
    6 5 6 5 6 5 5 6
    Sample Output
    3 6
    2 4 8
     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <algorithm>
     6 #include <cmath>
     7 #include <time.h>
     8 #include <string>
     9 #include <map>
    10 #include <stack>
    11 #include <vector>
    12 #include <set>
    13 #include <queue>
    14 #define inf 0x7fffffff
    15 #define mod 10000
    16 #define met(a,b) memset(a,b,sizeof a)
    17 typedef long long ll;
    18 using namespace std;
    19 const int N = 100;
    20 const int M = 100000;
    21 const int INF = 0x3f3f3f3f;
    22 int x;
    23 int n, a[100002], b[100002];
    24 int main()
    25 {
    26     int  t;
    27     scanf("%d", &t);
    28     while(t--)
    29     {
    30         scanf("%d", &n);
    31         memset(a, 0, sizeof(a));
    32         memset(b, 0, sizeof(b));
    33         for(int i = 0; i < n; i++)
    34         {
    35             scanf("%d", &b[i]);
    36             a[b[i]]++;
    37         }
    38         int c[1000];
    39         int ans = 0;
    40         for(int i = 1; i*i <= n; i++)
    41         {
    42             if(i*i == n) c[++ans] = i;
    43             else if(n%i == 0)
    44             {
    45                 c[++ans] = i;
    46                 c[++ans] = n/i;
    47             }
    48 
    49         }
    50         sort(c+1, c+1+ans);
    51         for(int i = 1; i <= ans; i++)
    52         {
    53             int flag = 1;
    54             for(int j = 1; j <= n; j++)
    55             {
    56                 if(a[j] > 0 && a[j]%c[i] != 0)
    57                 {
    58                     flag = 0;
    59                     break;
    60                 }
    61             }
    62             if(!flag) c[i] = -1;
    63         }
    64         int first = 1;
    65         for(int i = ans; i >= 1; i--)
    66         {
    67             if(c[i] > 0)
    68             {
    69                 if(first)
    70                 {
    71                     first = 0;
    72                     printf("%d", n/c[i]);
    73                 }
    74                 else printf(" %d", n/c[i]);
    75             }
    76 
    77         }
    78         printf("
    ");
    79 
    80     }
    81 }

    C、D待补
  • 相关阅读:
    JUC并发工具包之Semaphore
    Linux命令
    uWSGI
    数据库 MySQL 练习
    c++
    c++ 初阶
    Git
    MySQl 和 Redis
    MySQL 查询
    MySQL 命令
  • 原文地址:https://www.cnblogs.com/cshg/p/5926462.html
Copyright © 2020-2023  润新知