首页 > 代码库 > HNU 12869 Sequence(循环节)

HNU 12869 Sequence(循环节)

题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12869

解题报告:看到n的范围这么大,一看就是找规律,把前30个打出来之后就找到了循环节,循环节从第25个开始,长度为6。离线打表,把所有结果都打出来了。

 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 int ans1[30] = {0, 7 1,2,4,8,16,23,46,29,58,116,223,446,289,578,1156,1223,2446,2489,4789,5789,11578,12356,12247,24449}; 8 int ans2[30] = {48889,77789,155578,111356,122227,244445}; 9 int main()10 {11     int n;12     while(scanf("%d",&n)!=EOF)13     {14         if(n <= 24)15         printf("%d\n",ans1[n]);16         else printf("%d\n",ans2[(n - 25) % 6]);17     }18 /*    int n,que[30];19     while(scanf("%d",&n)!=EOF)20     {21         int temp = 1;22         for(int i = 1;i <= n;++i)23         {24             printf("%d,",temp);25             temp *= 2;26             int f = 0;27             while(temp)28             {29                 que[f++] = temp % 10;30                 temp /= 10;31             }32             sort(que,que+f);33             for(int j = 0;j < f;++j)34             temp = 10 * temp + que[j];35         }36     }37     return 0;*/38 }
View Code