superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

POJ 2183 - Bovine Math Geniuses

Posted on 2008-06-22 09:44 superman 阅读(280) 评论(0)  编辑 收藏 引用 所属分类: POJ
 1 /* Accepted 588K 0MS G++ 1469B */
 2 #include <string>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int cnt[10][10][10][10][10][10];
 8 
 9 int main()
10 {
11     char num[6];
12     for(int i = 0; i < 6; i++)
13     {
14         cin >> num[i];
15         num[i] -= '0';
16     }
17     
18     cnt[num[0]][num[1]][num[2]][num[3]][num[4]][num[5]] = 1;
19     
20     while(true)
21     {
22         int n = 0;
23         for(int i = 1; i < 6 - 1; i++)
24             n = n * 10 + num[i];
25         
26         n = n * n;
27         
28         char x[6];
29         for(int i = 6 - 1; i >= 0; i--)
30         {
31             x[i] = n % 10;
32             n /= 10;
33         }
34         
35         if(cnt[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]])
36         {
37             int i = 0;
38             while(x[i] == 0 && i < 6)
39                 i++;
40             if(i == 6)
41                 cout << 0;
42             while(i < 6)
43                 cout << int(x[i++]);
44             
45             int a = cnt[num[0]][num[1]][num[2]][num[3]][num[4]][num[5]] + 1;
46             int b = cnt[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]];
47             cout << ' ' << a - b << ' ' << a - 1 << endl;
48             break;
49         }
50         
51         cnt[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]]
52          = cnt[num[0]][num[1]][num[2]][num[3]][num[4]][num[5]] + 1;
53         
54         for(int i = 0; i < 6; i++)
55             num[i] = x[i];
56     }
57     
58     return 0;
59 }
60 

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理