• hdu 2609 How many 最小表示法


    How many

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


    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
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <algorithm>
     4 #include <string.h>
     5 #include <set>
     6 using namespace std;
     7 set<string>ss;
     8 void make(char a[],int x,int l)
     9 {
    10     char b[150];
    11     int i;
    12     for(i=0; i<l; i++)
    13         b[i]=a[x+i>=l?x+i-l:x+i];
    14     b[i]='';
    15     ss.insert(b);
    16 }
    17 void moremin(char a[])
    18 {
    19     int len=strlen(a);
    20     int i,j,k,t;
    21     k=i=0;
    22     j=1;
    23     while(i<len&&j<len&&k<len)
    24     {
    25         int t=a[i+k>=len?i+k-len:i+k]-a[j+k>=len?j+k-len:j+k];
    26         if(!t)k++;
    27         else
    28         {
    29             if(t>0) i+=k+1;
    30             else j+=k+1;
    31             if(i==j)j++;
    32             k=0;
    33         }
    34     }
    35     make(a,(i>j?j:i),len);
    36 }
    37 int main()
    38 {
    39     int n;
    40     char a[150];
    41     while(~scanf("%d",&n))
    42     {
    43         ss.clear();
    44         while(n--)
    45         {
    46             scanf("%s",a);
    47             moremin(a);
    48         }
    49         cout<<ss.size()<<endl;
    50     }
    51 }
    View Code
     
  • 相关阅读:
    Visual Studio技巧之打造拥有自己标识的代码模板
    arcgis 10.1 错误(TCP_NODELAY NOT enabled)
    中秋节快乐
    调Windows 7的图片浏览器查看图片
    NetCFSvcUtil.exe and Windows 7
    win7下IIS错误:"无法访问请求的页面,因为该页的相关配置数据无效"的解决方法(转)
    卫星地图下载软件WebImageDowns
    出差陕西镇安
    打印完税证明
    c#定义全局条件编译符号
  • 原文地址:https://www.cnblogs.com/ERKE/p/3832893.html
Copyright © 2020-2023  润新知