zoukankan      html  css  js  c++  java
  • hdu2609 How many

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2609

    题目:

    How many

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2625    Accepted Submission(s): 1135


    Problem Description
    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me
    How many kinds of necklaces total have.(if two necklaces can equal by rotating ,we say the two necklaces are some).
    For example 0110 express a necklace, you can rotate it. 0110 -> 1100 -> 1001 -> 0011->0110.
     
    Input
    The input contains multiple test cases.
    Each test case include: first one integers n. (2<=n<=10000)
    Next n lines follow. Each line has a equal length character string. (string only include '0','1').
     
    Output
    For each test case output a integer , how many different necklaces.
     
    Sample Input
    4 0110 1100 1001 0011 4 1010 0101 1000 0001
     
    Sample Output
    1 2
     
    Author
    yifenfei
     
    Source
     
    Recommend
    yifenfei
     
    思路:最大最小表示法+set
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <set>
     5 #include <string>
     6 using namespace std;
     7 
     8 #define MP make_pair
     9 #define PB push_back
    10 typedef long long LL;
    11 const double eps=1e-8;
    12 const int K=1e6+7;
    13 const int mod=1e9+7;
    14 
    15 char sb[205];
    16 //ff为真表示最小,为假表示最大
    17 //S串应该为原串复制两次后的字符串
    18 int mx_mi_express(char *S,bool ff,int len)
    19 {
    20     int i=0,j=1,k;
    21     while(i<len&&j<len)
    22     {
    23         k=0;
    24         while(k<len&&S[i+k]==S[j+k]) k++;
    25         if(k==len)  return i<=j?i:j;
    26         if((ff&&S[i+k]>S[j+k]) || (!ff&&S[i+k]<S[j+k]))
    27         {
    28             if(i+k+1>j) i=i+k+1;
    29             else    i=j+1;
    30         }
    31         else if((ff&&S[i+k]<S[j+k]) || (!ff&&S[i+k]>S[j+k]))
    32         {
    33             if(j+k+1>i) j=j+k+1;
    34             else    j=i+1;
    35         }
    36     }
    37     return i<=j?i:j;
    38 }
    39 string tmp;
    40 set<string>st;
    41 int main(void)
    42 {
    43     int t,n,len;
    44     while(scanf("%d",&n)==1&&n)
    45     {
    46         st.clear(),tmp.clear(),len=0;
    47         for(int i=1,be;i<=n;i++)
    48         {
    49             scanf("%s",sb);
    50             if(!len)
    51             {
    52                 len=strlen(sb);
    53                 for(int j=0;j<len;j++)
    54                     tmp+='0';
    55             }
    56             for(int j=0;j<len;j++)
    57                 sb[j+len]=sb[j];
    58             be=mx_mi_express(sb,1,len);
    59             for(int j=0;j<len;j++)
    60                 tmp[j]=sb[j+be];
    61             st.insert(tmp);
    62         }
    63         printf("%d
    ",st.size());
    64     }
    65     return 0;
    66 }
  • 相关阅读:
    JQuery基础知识总结
    抽象方法与虚方法
    关于性能的几个术语
    T-SQL基础知识
    学习materialize
    VS2013 启用avalon 智能提示 Intelligence
    推荐一款开源的C#TCP通讯框架
    js/jquery 获取本地文件的文件路劲 获取input框中type=‘file’ 中的文件路径(转载)
    HTML5的 input:file上传类型控制(转载)
    tinymce4.x 上传本地图片 (转载)
  • 原文地址:https://www.cnblogs.com/weeping/p/6670265.html
Copyright © 2011-2022 走看看