AmazingCounters.com

USACO Runaround Numbers

题目大意:问最近的比n大的循环数是多少

思路:第n遍暴力大法好

 

 1 /*{
 2 ID:a4298442
 3 PROB:runround
 4 LANG:C++
 5 }
 6 */
 7 #include<iostream>
 8 #include<fstream>
 9 #define maxn 500
10 using namespace std;
11 ifstream fin("runround.in");
12 ofstream fout("runround.out");
13 //#define fin cin
14 //#define fout cout
15 int runround(long long x)
16 {
17     int digital[maxn]={0},num[maxn],h=0;
18     bool visit[maxn]={0},visit2[11]={0};
19     while(x!=0)
20     {
21         digital[++h]=x%10;
22         if(visit2[digital[h]]==1)return 0;
23         visit2[digital[h]]=1;
24         if(digital[h]==0)return 0;
25         x/=10;
26     }
27     for(int i=h;i>=1;i--)num[i-1]=digital[h-i+1];
28     int pos=0;
29     for(int i=1;i<=h;i++)
30     {
31         visit[pos]=1;
32         int u=num[pos];
33         pos=(u+pos)%h;
34         if(visit[pos]==1 && i!=h)return 0;
35         if(i==h && pos!=0)return 0;
36     }
37     return 1;
38 }
39 int main()
40 {
41     int n;
42     fin>>n;
43     for(long long i=n+1;;i++)
44     {
45         if(runround(i))
46         {
47             fout<<i<<endl;
48             break;
49         }
50     }
51     return 0;
52 }

 

posted @ 2015-03-07 17:00  philippica  阅读(170)  评论(0编辑  收藏  举报