zoukankan      html  css  js  c++  java
  • hdu 4034 2011成都赛区网络赛 逆向floyd **

    给出一个最短路邻接矩阵,求出构图的最小边数

    正常的floyd的k放在最外面是为了防止i到j的距离被提前确定,而逆向的floyd,i到j的距离已经确定,所以需要在i到j之间枚举k,注意需要break,否则会多删除

    Sample Input

    3
    3
    0 1 1
    1 0 1
    1 1 0
    3
    0 1 3 
    4 0 2
    7 3 0
    3
    0 1 4
    1 0 2
    4 2 0

    Sample Output
    Case 1: 6
    Case 2: 4
    Case 3: impossible

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<queue>
     7 #include<map>
     8 using namespace std;
     9 #define MOD 1000000007
    10 const int INF=0x3f3f3f3f;
    11 const double eps=1e-5;
    12 typedef long long ll;
    13 #define cl(a) memset(a,0,sizeof(a))
    14 #define ts printf("*****
    ");
    15 const int MAXN=1005;
    16 int n,m,tt,ans;
    17 int c[MAXN][MAXN];
    18 bool fun()
    19 {
    20     ans=0;
    21     int i,j,k;
    22     for(i=0;i<n;i++)
    23     {
    24         for(j=0;j<n;j++)
    25         {
    26             for(k=0;k<n;k++)
    27             {
    28                 if(i!=j&&i!=k&&j!=k)
    29                 {
    30                     if(c[i][k]+c[k][j]==c[i][j])
    31                     {
    32                         ans--;
    33                         break;
    34                     }
    35                     if(c[i][k]+c[k][j]<c[i][j])    return 0;
    36                 }
    37 
    38             }
    39         }
    40     }
    41     return 1;
    42 }
    43 int main()
    44 {
    45     int i,j,k;
    46     #ifndef ONLINE_JUDGE
    47     freopen("1.in","r",stdin);
    48     #endif
    49     scanf("%d",&tt);
    50     int ca=1;
    51     while(tt--)
    52     {
    53         scanf("%d",&n);
    54         printf("Case %d: ",ca++);
    55         for(i=0;i<n;i++)
    56         {
    57             for(j=0;j<n;j++)
    58             {
    59                 scanf("%d",&c[i][j]);
    60             }
    61         }
    62         if(fun())
    63         {
    64             printf("%d
    ",n*n+ans-n);
    65         }
    66         else    printf("impossible
    ");
    67     }
    68 }
  • 相关阅读:
    [svc]frp内网穿透
    [svc]caffe安装笔记
    [na]icmp重定向
    [tools]python的mkdocs模块分分钟将md搞成一个网站
    [svc]samba服务搭建
    [ci] jenkins的Timestamper插件-让日志显示时间
    [k8s]subpath解决cm覆盖目录问题
    struts2+jquery+ajax实现上传&&校验实例
    java String.split方法是用注意点(转)
    loadrunner java协议脚本要点
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4312121.html
Copyright © 2011-2022 走看看