标签:otto eps std first acm bool double code i++
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2609
题目:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2625 Accepted Submission(s): 1135
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 }
标签:otto eps std first acm bool double code i++
原文地址:http://www.cnblogs.com/weeping/p/6670265.html