POJ 1125(Floyd)

裸Floyd


Program P1125;
const
   maxn=100;
   maxedge=10;
   NULL=-2139062144;
var
   n,i,j,k,m,v,t,ans:longint;
   f:array[1..maxn,1..maxn] of longint;
function max(a,b:longint):longint;
begin
   if a<b then exit(b) else exit(a);
end;
begin
   read(n);
   while (n<>0) do
   begin
      fillchar(f,sizeof(f),128);
      for i:=1 to n do
      begin
         f[i,i]:=0;
         read(m);
         for j:=1 to m do
         begin
            read(v,t);
            f[i,v]:=t;
         end;
      end;

      for k:=1 to n do
         for i:=1 to n do
            for j:=1 to n do
               if (f[i,k]<>NULL) and (f[k,j]<>NULL) then
                  if (f[i,k]+f[k,j]<f[i,j]) or (f[i,j]=NULL) then f[i,j]:=f[i,k]+f[k,j];
      ans:=maxlongint;

      v:=0;
      for i:=1 to n do
      begin
         t:=f[i,1];
         for j:=1 to n do
         begin
            if f[i,j]=NULL then break else t:=max(f[i,j],t);
         end;
         if f[i,j]=NULL then continue;
         if t<ans then begin v:=i; ans:=t; end;

      end;
      if (ans=maxlongint) then writeln('disjoint') else writeln(v,' ',ans);



      read(n);
   end;
end.


1) { JOptionPane.showMessageDialog(this, "请选择要删除的图书!", "提示", JOptionPane.WARNING_MESSAGE); } else { 这是一道经典的最短路问题,可以使用Dijkstra算法或者Floyd算法来解决。 D String bookId = bookInfoTable.getValueAt(selectedRow, 0).toString(); int option = JOptionPane.showConfirmDialog(this, "确定要删除编号为 " + bookId + " 的图书吗?", "提示", JOptionPane.YES_NO_OPTION); if (optionijkstra算法的基本思想是从起点开始,依次遍历所有节点,每次选择距离起点最 == JOptionPane.YES_OPTION) { deleteBookInfo(bookId); loadBookInfo(); } } } else if (e.getSource() == backButton) { new MainFrame(); setVisible(false); } } private void loadBookInfo() { 近的节点进行松弛操作,直到到达终点或者所有节点都被遍历完。 Floyd算法则 tableModel.setRowCount(0); Connection conn = null; Statement stmt = null; ResultSet rs = null; try { 是通过动态规划求解所有节点之间的最短路径。具体来说,利用一个二维数组存 conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/book_management?useSSL=false&serverTimezone=UTC", "root", "root"); stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM book_info"); while (rs.next())储任意两个节点之间的最短距离,然后依次考虑增加中间节点,更新所有节点 { Object[] rowData = new Object[6]; rowData[0] = rs.getInt("book_id"); rowData[1]之间的距离,直到所有节点都被考虑过。 无论使用哪种算法,都需要先构建 = rs.getString("book_name"); rowData[2] = rs.getString("author"); rowData[3] = rs.getString("publisher"); rowData[4] = rs.getDouble("price"); rowData[5] = rs.getInt("quantity"); tableModel.addRow(row出图的邻接矩阵或邻接表,然后根据算法的要求进行处理即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值