Luogu P1467 循环数 Runaround Numbers
按道理来说,我应该在打树链剖分的,但是好难啊qwq,划水ing。。
傻逼题。但还是花了我不少时间调。。。
#include<cstdio>
#include<cstring>
long long a,b;
int len=0,c[10010],d[12],e[12],sum=0;
int suzu(long long a)
{
b=10;len=1;
while(1)
{
if(a/b>0)
{
len++;
b*=10;
}
else
break;
}
int t=a,l=len;
while(l>0)
{
c[l]=t%10;
if(d[c[l]]==1||d[0]==1)
{
return 0;
}
d[c[l]]=1;
t/=10;
l--;
}
return 1;
}
int work()
{
int x,loc;
x=1;
e[1]=1;
sum=1;
while(1)
{
int t=c[x];
loc=(x+t)%len;
if(loc==0)loc=len;//!!!!!!!!!
if(sum==len)
{
if(loc==1)return 1;
else return 0;
}
if(e[loc]==0)
{
e[loc]=1;
sum++;
}
else if(e[loc]==1)
{
return 0;
}
x=loc;loc=0;
}
}
int main()
{
scanf("%lld",&a);
while(1)
{
a++;
memset(c,0,sizeof(c));
memset(d,0,sizeof(d));
memset(e,0,sizeof(e));
sum=0;
//suzu(a);
if(suzu(a)==0)
{
continue;
}
if(work())
{
printf("%lld",a);
return 0;
}
}
for(int i=1;i<=len;i++)
{
printf("%d",c[i]);
}
}