| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
problem3708Fx(m)=k;
可以化为Fx(z)=w;0<z<d;
又0<ai<d,Fx(z)=F(x-1)(az);
所以可以迭代判断Fx(z)=w是否成立
以上没错吧,可为什么总是rt呢?
#include<stdio.h>
int main(void)
{
int d,*a,*b,*c,i,j,x;
__int64 k,m;
while(1)
{
scanf("%d",&d);
if(d==-1)
break;
a=(int*)malloc(sizeof(int)*d);
c=(int*)malloc(sizeof(int)*d);
b=(int*)malloc(sizeof(int)*d);
for(i=1;i<d;scanf("%d",a+i),i++);
for(i=0;i<d;scanf("%d",b+i),i++);
scanf("%I64d", &m);
scanf("%I64d", &k);
i=0;
while(m>=d)
{
if((k-*(b+m%d))%d!=0)
{
i++;
break;
}
k=(k-*(b+m%d))/d;
m=(m-m%d)/d;
}
if(i==1)
printf("NO\n");
else
{
x=1;
for(j=1;j<d;j++)
*(c+j)=0;
while(*(a+m)!=k)
{
x++;
if(*(c+m)!=1)
*(c+m)=1;
else
{
printf("NO\n");
i=1;
break;
}
m=*(a+m);
if(m>=d||m<1)//
{
i=1;
break;
}
}
if(i!=1)
printf("%d\n",x);
}
free(a);
free(b);
free(c);
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator