zoukankan      html  css  js  c++  java
  • HDU 2609 How many

    解题思路:最大or最小表示法找出最大or最小,然后重组字符串,用set去重,看set.size()即可

     1 #include <iostream>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <string>
     5 #include <set>
     6 using namespace std;
     7 
     8 int Len;
     9 set<string> result;
    10 
    11 int FindMin(string a)
    12 {
    13     int i = 0, j = 1, k = 0;
    14     while (i < Len && j < Len && k < Len)
    15     {
    16         if (a[(i + k) % Len] == a[(j + k) % Len])
    17             k++;
    18         else if (a[(i + k) % Len] > a[(j + k) % Len])
    19         {
    20             i = i + k + 1;
    21             k = 0;
    22         }
    23         else
    24         {
    25             j = j + k + 1;
    26             k = 0;
    27         }
    28         if (i == j)
    29             j++;
    30     }
    31 
    32     return min(i, j);
    33 }
    34 
    35 int main()
    36 {
    37     ios::sync_with_stdio(false);
    38     int cas;
    39     while (cin >> cas)
    40     {
    41         for (int i = 0; i < cas; ++i)
    42         {
    43             string s, temp;
    44             cin >> s;
    45             Len = s.size();
    46             int k = FindMin(s);
    47             for (int j = k; j < Len; ++j)
    48                 temp += s[j];
    49             for (int j = 0; j < k; ++j)
    50                 temp += s[j];
    51             result.insert(temp);
    52         }
    53 
    54         cout << result.size() << endl;
    55         result.clear();
    56     }
    57 
    58     return 0;
    59 }
  • 相关阅读:
    十三、Sleuth分布式请求链路追踪
    十二、SpringCloud Stream消息驱动
    十一、SpringCloud Bus 消息总线
    Linux命令(权限管理)
    Linux命令(文件管理)
    Linux的文件和目录
    Linux介绍及安装
    Docker
    Nginx
    13、SpringBoot整合Mybatis-Plus
  • 原文地址:https://www.cnblogs.com/ducklu/p/9121693.html
Copyright © 2011-2022 走看看