POJ 1502 水 dij
题意:给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的更多相关文章
- 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 ...
- POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)
MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...
- poj 1502 最短路+坑爹题意
链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- Invitation Cards POJ 1511 SPFA || dij + heap
http://poj.org/problem?id=1511 求解从1去其他顶点的最短距离之和. 加上其他顶点到1的最短距离之和. 边是单向的. 第一种很容易,直接一个最短路, 然后第二个,需要把边反 ...
- POJ 1502 MPI Maelstrom(最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4017 Accepted: 2412 Des ...
- POJ 2502 Subway dij
这个题的输入输出注意一下就好 #include<cstdio> #include<cstring> #include<queue> #include<cstd ...
- POJ 1847 Tram dij
分析:d[i]表示到i点,最少的操作数 #include<cstdio> #include<cstring> #include<queue> #include< ...
- poj 1269 水题
题目链接:http://poj.org/problem?id=1269 #include<cstdio> #include<cstring> #include<cmath ...
随机推荐
- LR 两种录制:html与url
一直在使用LR,对于Html_based script和Url-based script 两种录制方式之间,要如何选择,仍是一知半解.最近测试时遇到同样的业务功能,两种录制方式的脚本,单次执行时间差别 ...
- uva1611 Crane
类似煎饼,先把1放到1,之后是子问题 (先放到前一半,再放到开头,两次操作)(任何位置,最多一次就可以放到前一半)) #include<iostream> #include<ve ...
- libcmt.lb libcmtd.lib与MSVCRTD.lib的冲突解决
system("pause"); 这个函数存在于MSVCRTD.lib库中: 当要使用system("pause")这个函数,且libcmt.lb libcmt ...
- C-基础:memcpy、memset、memmove、memcmp、memchr
一,原型 void * memcpy ( void * destination, const void * source, size_t num ); 功能:将以source作为起始地址的数据复制nu ...
- Hibernate-02 HQL实用技术
学习任务 Query接口的使用 HQL基本用法 动态参数绑定查询 HQL的使用 Hibernate支持三种查询方式:HQL查询.Criateria查询.Native SQL查询. HQL是Hibern ...
- select onchange事件的使用
<select name="expireDay" id="expireDay" class="form-control" onchan ...
- windows10下Anaconda的安装与tensorflow、opencv的安装与环境配置
刚开始学习tensorflow和opencv这一块的知识,所以用博客这个平台来把自己这段学习的经历与感想写下来. tensorflow和opencv则用Anaconda来下载和配置环境. 下载Anac ...
- JAVA:windows myeclipse jdk tomcat maven 完美搭建
文章来源:http://www.cnblogs.com/hello-tl/p/8305027.html 0.下载所需安装包 jdk-7u71-windows-x64.exe 链接:http://p ...
- git 项目相关
工具篇:Sourcetree 和 Git Bash Sourcetree Git一款非常好用的可视化工具,方便管理项目.下载地址 https://www.sourcetreeapp.com/ Git ...
- tornado框架基础09-cookie和session
01 cookie 在上节,我们简单了解了登录过程,但是很明显,每次都需要登录,但是在平常逛网站的只需要登录一次,那么网站是如何记录登录信息的呢? 有没有什么办法可以让浏览器记住登录信息,下次再次打开 ...