#include<cmath>
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
#define ll long long int
#define INF 0x7fffffffffffffff
ll mask(ll x,string str,ll dist)
{
ll re=INF,y=0,len;
len=str.size();
for(int i=0;i<len;i++)
if( !(x&(1LL<<i)) || str[(i+dist)%len]>re )continue;
else if((int)str[(i+dist)%len]<re)
{
re=(ll)str[(i+dist)%len];
y=1LL<<i;
}
else
y^=1LL<<i;
return y;
}
int main()
{
ll x,dist=0,len;
string str;
cin>>str;//60 len strings
len=str.size();
x=(1LL<<len)-1;
do
{x=mask(x,str,dist++);}while(x&(x-1) && dist<=len);
cout<<"Index #"<<log2(x&-x)+1<<endl;
return 0;
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.