superman

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

ZOJ 1221 - Risk

Posted on 2008-05-03 22:59 superman 阅读(179) 评论(0)  编辑 收藏 引用 所属分类: ZOJ
 1 /* Accepted 1221 C++ 00:00.00 840K */
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int Test = 0;
 9     while(true)
10     {
11         unsigned map[21][21];
12         memset(map, 255sizeof(map));
13         
14         for(int s = 1; s < 20; s++)
15         {
16             int n, t;
17             if(cin >> n == false)
18                 return 0;
19             while(n--)
20             {
21                 cin >> t;
22                 map[s][t] = map[t][s] = 1
23             }
24         }
25         
26         for(int k = 1; k <= 20; k++)
27         for(int i = 1; i <= 20; i++)
28         for(int j = 1; j <= 20; j++)
29             if(map[i][k] != UINT_MAX && map[k][j] != UINT_MAX)
30                 map[i][j] <?= (map[i][k] + map[j][k]);
31         
32         int n, s, t; cin >> n;
33         
34         cout << "Test Set #" << ++Test << endl;
35         while(n--)
36         {
37             cin >> s >> t;
38             cout << s << " to " << t << "" << map[s][t] << endl;
39         }
40         cout << endl;
41     }
42     
43     return 0;
44 }
45 

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