日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu2609 How many

發布時間:2024/7/19 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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\n",st.size()); 64 } 65 return 0; 66 }

?

轉載于:https://www.cnblogs.com/weeping/p/6670265.html

總結

以上是生活随笔為你收集整理的hdu2609 How many的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。