Circle Line

http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1956&cid=1151

floyd: 用 g++ 提交

View Code
 1 #include <stdio.h>  
 2 #include <string.h>  
 3 const int inf = 1<<28;  
 4 const int maxn = 1001;  
 5 int map[maxn][maxn];  
 6 int n ;  
 7 void floyd()  
 8 {  
 9     for(int k = 1; k <= n; k++)  
10     {  
11         for(int i = 1; i <= n; i++)  
12         {  
13             for(int j = 1; j <= n; j++)  
14             {  
15                 if(map[i][k]+map[k][j] < map[i][j])  
16                 {  
17                     map[i][j] = map[i][k]+map[k][j] ;  
18                 }  
19             }  
20         }  
21     }  
22 }  
23   
24 void init()  
25 {  
26     for(int i = 1; i <= n; i++)  
27     {  
28         for(int j = 1; j <= n; j++)  
29         {  
30             map[i][j] = inf;  
31         }  
32         map[i][i] = 0;  
33     }  
34 }  
35   
36 int main()  
37 {  
38     while(~scanf("%d", &n))  
39     {  
40         init();  
41         int a;  
42         int s, t ;  
43         for(int i = 1; i <= n-1; i++)  
44         {  
45             scanf("%d", &a);  
46             map[i][i+1] = a;  
47             map[i+1][i] = a;  
48         }  
49         scanf("%d",&a);  
50         map[n][1] = a;  
51         map[1][n] = a;  
52         floyd();  
53         scanf("%d %d", &s, &t);  
54         if(map[s][t]>map[t][s])  
55          printf("%d\n", map[t][s]);  
56          else printf("%d\n",map[s][t]);  
57   
58     }  
59     return 0;  
60 }  
61    

 

转载于:https://www.cnblogs.com/yelan/archive/2013/03/03/2941979.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值