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 ...
随机推荐
- vue项目中快捷语法糖
1.Vue.js是渐进式框架,采用自底向上增量开发的设计基于MVVM思想. 2.Vue 完全有能力驱动采用单文件组件和Vue生态系统支持的库开发的复杂单页应用. 3.Vue.js 的目标是通过尽可能简 ...
- SAP CRM调查问卷的评分和图表显示功能介绍
SAP CRM里我们使用事务码CRM_SURVEY_SUITE创建一个调查问卷(Survey): 其中调查问卷的问题和答案均可分配权值(Rate),最后该问卷总的分数等于每个问题的权值乘以客户选择答案 ...
- Graveyard LA3708
白书第一章例题4 思维. 先固定一点不动,假设最后一共N个点,那么编号为0,1,...N-1, 0不动,原来的n个点分别占据i/n*N的位置(记为pos),移动到pos四舍五入的位置即可. 证明一:有 ...
- MATLAB读取每个文件夹下的badcsv文件后合并为总的badexcel文件
clear; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读取子文件夹中bad.csv数据%并把所有数据写到一个excel文件中%%%%%%%%%%%%%%%%%% ...
- LinkedHashMap/HashMap(数҉据҉缓҉存҉准҉备҉)
顾名思义LinkedHashMap是比HashMap多了一个链表的结构.与HashMap相比LinkedHashMap维护的是一个具有双重链表的HashMap,LinkedHashMap支持2中排序一 ...
- 217. Contains Duplicate@python
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- Shell数值比较
Shell数值比较 比较 描述 n1 -eq n2 检查n1是否与n2相等 n1 -ge n2 检查n1是否大于或等于n2 n1 -gt n2 检查n1是否大于n2 n1 -le n2 检查n1是否小 ...
- LInux设备驱动分析—— kmalloc和kzalloc函数
今晚在研究EVM5728开发板上面Linux系统的IIC设备驱动程序,偶然之间看到驱动程序中有一处使用了kzalloc函数,本人之前都是使用Linux内核提供的kmalloc / kfree函数来给设 ...
- Gameia
F - Gameia HDU - 6105 Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes l ...
- (5) openssl speed(测试算法性能)和openssl rand(生成随机数)
1.1 openssl speed 测试加密算法的性能 支持的算法有: openssl speed [md2] [mdc2] [md5] [hmac] [sha1] [rmd160] [idea-cb ...