Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Floyd算法

Posted by zhuangzebo at 2011-09-21 13:16:24 on Problem 3615
用Floyd,可以说是加了dp的思想就可以过了
#define INF  1<<30 
for(k = 1; k <= n; k++) {
        for(i = 1; i <= n; i++)
        for(j = 1; j <= n; j++) {
            if(map[i][k] != INF && map[k][j] != INF) {
                map[i][j] = min(max(map[i][k], map[k][j]), map[i][j]);
            }
        }
 }
////////////////////////////////////////////////////////
 for(i = 0; i < t; i++) {
      scanf("%d%d", &x, &y);
      if(map[x][y] != INF) printf("%d\n", map[x][y]);
      else printf("-1\n");
}
这样就OK啦~

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator