HDU 2609 How many (minimum notation)

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
 
Ideas: beginning to think of the smallest representation, have been thinking with a bool sign [100000] array to determine which string is repeated, but found this approach very troublesome, and I also wa up. Later, with a set heavy sentence, my mother no longer have to worry about my study, so easy ~
 
///
///                            _ooOoo_
///                           o8888888o
///                           88" . "88
///                           (| -_- |)
///                           O\  =  /O
///                        ____/`---'\____
///                      .'  \\|     |//  `.
///                     /  \\|||  :  |||//  \
///                    /  _||||| -:- |||||-  \
///                    |   | \\\  -  /// |   |
///                    | \_|  ''\---/''  |   |
///                    \  .-\__  `-`  ___/-. /
///                  ___`. .'  /--.--\  `. . __
///               ."" '<  `.___\_<|>_/___.'  >'"".
///              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
///              \  \ `-.   \_ __\ /__ _/   .-` /  /
///         ======`-.____`-.___\_____/___.-`____.-'======
///                            `=---='
///        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///                      Buddha Bless, No Bug !
///
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <set>
using namespace std;
#define MAXN 100010
#define ll long long

string s;
int len, ans;

set<string>se;

int minma(string x)///最小表示法
{
    int len = x.size();
    int i = 0 , J = . 1 , K = 0 ;
     the while (I <len && J <K && len <len) /// If still within the range 
    {
         int T X = [(I + K)% len] - X [( K + J)% len]; /// Comparative lexicographical size between two characters 
        IF (T == 0 ) /// If the two are equal lexicographic order, comparing it with the forward 
            K ++ ;
         the else 
        { 
            IF ( T> 0 ) /// If x [(i + k)% len] lexicographic order than x [(j + k)% len] lexicographic order is large, x [i + 1] x [ i + 2] ... x [i + k] lexicographic order are [j + k] is greater than x, skip this section so that i 
                i + = K + . 1 ;
             the else ///If x [(j + k)% len] lexicographic order [(i + k)% len ] lexicographic order is greater than x, then x [j + 1] x [ j + 2] ... x [j + k] lexicographic order are [i + k] is greater than x, skip this section so that j 
                j = K + + . 1 ;
             IF (I == j) /// If i == j, let j points to the next a character 
                J ++ ; 
            K = 0 ; 
        } 
    } 
    return I <J? I: J; 
} 

int main () 
{ 
    int n-;
     the while (CIN >> n-) 
    { 
        se.clear (); 
        for ( int I = 0 ; I <n-; I ++ ) 
        {
            CIN >> S; 
            len = s.size ();
             int ID = minma (S); 
            S + = S; 
            se.insert (s.substr (ID, len)); /// with the set weight determination, equal removed portions 
        } 

        the printf ( " % D \ n- " , se.size ()); 
    } 
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/RootVount/p/11360063.html