Posted on 2009-03-30 17:23
superman 阅读(103)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 bool isRunaroundNumber(int num)
6 {
7 int n = 0;
8 int t, x[10], c[10] = { 0 };
9
10 while (num)
11 {
12 t = num % 10;
13
14 if ((c[t] += 1) > 1)
15 return false;
16
17 x[n++] = t;
18 num /= 10;
19 }
20
21 for (int i = 0; i < n / 2; i++)
22 swap(x[i], x[n - i - 1]);
23
24 //=============================
25 memset(c, 0, sizeof(c));
26
27 int p = 0;
28 for (int i = 0; i < n; i++)
29 {
30 c[p]++;
31 if (c[p] > 1)
32 return false;
33 p = (p + x[p]) % n;
34 }
35
36 return p == 0;
37 }
38
39 int main()
40 {
41 freopen("runround.in", "r", stdin);
42 freopen("runround.out", "w", stdout);
43
44 int m;
45
46 cin >> m;
47 for (int i = m + 1; true; i++)
48 if (isRunaroundNumber(i))
49 {
50 cout << i << endl;
51 break;
52 }
53
54 return 0;
55 }
56