题意:给N,表示N个节点。

给半个邻接矩阵,本身到本身的距离是0,边是双向的。当两个节点之间没有直接的边连接的时候,用x表示。

问从第一个节点到其他所有节点至少花费的时间。

这题唯一的处理是处理邻接矩阵的时候处理先当作字符串读入,然后处理一下数据,变成数据格式。

最后是输出第一个节点到其他所有节点最短路的最大值。

#include<stdio.h>
#include<string.h>
int n;
const int inf=;
int pho[][];
char tmp[][];
bool vis[];
int dis[];
void solve(int pos)
{
vis[pos]=;
for(int i=;i<=n;i++)
{
if(!vis[i]&&pho[pos][i]+dis[pos]<dis[i])
{
dis[i]=pho[pos][i]+dis[pos];
}
}
int next=inf;
int minn=inf;
for(int i=;i<=n;i++)
{
if(!vis[i])
{
if(minn>dis[i])
{
minn=dis[i];
next=i;
}
}
}
if(next<=n)
solve(next);
}
int main()
{
int len;
int num;
int ttt;
scanf("%d",&n);
getchar();
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
pho[i][j]=inf;
}
pho[i][i]=;
dis[i]=inf;
}
for(int i=;i<=n;i++)
{
gets(tmp[i]);
}
for(int i=;i<=n;i++)
{
num=;
len=strlen(tmp[i]);
tmp[i][len]=;
ttt=;
for(int j=;j<=len;j++)
{
if(tmp[i][j]==)
{
num++;
pho[num][i]=pho[i][num]=ttt;
ttt=;
}
else if(tmp[i][j]=='x')
{
ttt=inf;
}
else
{
ttt*=;
ttt+=tmp[i][j]-;
}
}
}
dis[]=;
solve();
int maxx=-;
for(int i=;i<=n;i++)
{
if(maxx<dis[i])
maxx=dis[i];
}
printf("%d\n",maxx);
}

POJ 1502 水 dij的更多相关文章

  1. POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)

    POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...

  2. POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)

    MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...

  3. poj 1502 最短路+坑爹题意

    链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  4. POJ 1502 MPI Maelstrom (Dijkstra)

    题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...

  5. Invitation Cards POJ 1511 SPFA || dij + heap

    http://poj.org/problem?id=1511 求解从1去其他顶点的最短距离之和. 加上其他顶点到1的最短距离之和. 边是单向的. 第一种很容易,直接一个最短路, 然后第二个,需要把边反 ...

  6. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

  7. POJ 2502 Subway dij

    这个题的输入输出注意一下就好 #include<cstdio> #include<cstring> #include<queue> #include<cstd ...

  8. POJ 1847 Tram dij

    分析:d[i]表示到i点,最少的操作数 #include<cstdio> #include<cstring> #include<queue> #include< ...

  9. poj 1269 水题

    题目链接:http://poj.org/problem?id=1269 #include<cstdio> #include<cstring> #include<cmath ...

随机推荐

  1. 关于maven source1.5报错

    是因为maven 默认是1.5编译的 <build>//加上这个配置,把编译给改掉试试 <pluginManagement> <plugins> <plugi ...

  2. JavaScript-条件循环

    JavaScript-条件循环 条件判断语句 if 语句 - 只有当指定条件为 true 时,使用该语句来执行代码 if (表达式){    当条件为 true 时执行的代码} if...else 语 ...

  3. edquota - 编辑用户配额

    SYNOPSIS(总览) edquota [ -p proto-username ] [ -u | -g ] username... edquota [ -u | -g ] -t DESCRIPTIO ...

  4. docker存储管理

    Docker 镜像的元数据 repository元数据 repository在本地的持久化文件存放于/var/lib/docker/image/overlay2/repositories.json中 ...

  5. linux 如何查看硬盘大小,内存大小等系统信息及硬件信息

    一.linux CPU大小[root@idc ~]# cat /proc/cpuinfo |grep "model name" && cat /proc/cpuin ...

  6. Memcached的安装和应用

    Memcached的安装 1.安装libeventlibevent是一个事件触发的网络库,适用于windows.linux.bsd等多种平台,内部使用 select.epoll.kqueue等系统调用 ...

  7. 16. PLUGINS

    16. PLUGINS PLUGINS表提供有关服务器插件的信息. PLUGINS表有以下列: PLUGIN_NAME :用于在诸如INSTALL PLUGIN和UNINSTALL PLUGIN之类的 ...

  8. UART中RTS、CTS

    RTS (Require ToSend,发送请求)为输出信号,用于指示本设备准备好可接收数据,低电平有效,低电平说明本设备可以接收数据. CTS (Clear ToSend,发送允许)为输入信号,用于 ...

  9. 跟http相关的

    http http 中     请求: 请求行    请求方式   采用协议   版本号     网址    请求头    客户端可以接受数据类型    可以接受语言     可以接受的压缩格式 请求 ...

  10. sql使用row_number()查询标记行号

    背景: 在分页功能中,记录需分页显示,需要row_number()函数标记行号. 数据表: 排序之前数据表显示: sql语句: select ROW_NUMBER() over(order by id ...