1837. Isenbaev's Number(floyd)
被数据结构部分打击的不行了 换地 刷点简单的 图论第一题 floyd水过
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<map>
using namespace std;
int w[][];
#define INF 0xfffffff
map<string,int>f;
struct node
{
char s[];
int id;
}p[];
bool cmp(node a,node b)
{
return strcmp(a.s,b.s)<;
}
int main()
{
int i,j,n,k,g=,u=;
char s1[],s2[],s3[];
for(i = ; i <= ; i++)
for(j = ; j <= ; j++)
w[i][j] = INF;
scanf("%d",&n);
for(i = ; i <= n ; i++)
{
scanf("%s%s%s",s1,s2,s3);
if(!f[s1])
{
g++;
f[s1] = g;
p[g].id = g;
if(strcmp(s1,"Isenbaev")==)
u = g;
strcpy(p[g].s,s1);
}
if(!f[s2])
{
g++;
f[s2] = g;
p[g].id = g;
if(strcmp(s2,"Isenbaev")==)
u = g;
strcpy(p[g].s,s2);
}
if(!f[s3])
{
g++;
f[s3] = g;
p[g].id = g;
if(strcmp(s3,"Isenbaev")==)
u = g;
strcpy(p[g].s,s3);
}
w[f[s1]][f[s2]] = ;
w[f[s2]][f[s1]] = ;
w[f[s1]][f[s3]] = ;
w[f[s3]][f[s1]] = ;
w[f[s2]][f[s3]] = ;
w[f[s3]][f[s2]] = ;
}
for(i = ; i <= g ; i++)
w[i][i] = ;
for(i = ;i <= g ; i++)
for(j = ; j <= g ; j++)
for(k = ; k <= g ; k++)
if(w[j][k]>w[j][i]+w[i][k])
w[j][k] = w[j][i]+w[i][k];
sort(p+,p+g+,cmp);
for(i = ; i <= g ; i++)
{
if(u&&w[p[i].id][u]!=INF)
printf("%s %d\n",p[i].s,w[p[i].id][u]);
else
printf("%s undefined\n",p[i].s);
}
return ;
}
1837. Isenbaev's Number(floyd)的更多相关文章
- ural 1837 Isenbaev's Number
http://acm.timus.ru/problem.aspx?space=1&num=1837 #include <cstdio> #include <cstring&g ...
- ural 1837. Isenbaev's Number bfs
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1837 描述: Isenbaev是国外的一个大牛. 现在有许多人要参加ACM ICPC. ...
- URAL 1837. Isenbaev's Number (map + Dijkstra || BFS)
1837. Isenbaev's Number Time limit: 0.5 second Memory limit: 64 MB Vladislav Isenbaev is a two-time ...
- [LeetCode] 287. Find the Duplicate Number(Floyd判圈算法)
传送门 Description Given an array nums containing n + 1 integers where each integer is between 1 and n ...
- 图论-最短路径 floyd/dijkstra-Find the City With the Smallest Number of Neighbors at a Threshold Distance
2020-01-30 22:22:58 问题描述: 问题求解: 解法一:floyd 这个题目一看就是floyd解最合适,因为是要求多源最短路,floyd算法是最合适的,时间复杂度为O(n ^ 3). ...
- floyd算法学习笔记
算法思路 路径矩阵 通过一个图的权值矩阵求出它的每两点间的最短路径矩阵.从图的带权邻接矩阵A=[a(i,j)] n×n开始,递归地进行n次更新,即由矩阵D(0)=A,按一个公式,构造出矩阵D(1):又 ...
- UVA10048 Audiophobia[Floyd变形]
UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...
- Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...
- ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩
HDU 5418 Victor and World Time Limit:2000MS Memory Limit:131072KB 64bit IO Format:%I64d & ...
随机推荐
- Jquery ajax basic
$.ajax({ url: "test.aspx?action=testaction", contentType: "application/json; charset= ...
- Cassandra1.2文档学习(12)—— hint机制
参考文档:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/dml/dml_about_ ...
- android studio引入第三方包记录
1.添加jar文件 将jar文件复制至app module目录下的libs文件夹下,然后打开app module目录下的build.gradle配置文件,在dependencies项中添加配置命令,这 ...
- Inside Microsoft SQL Server 2008: T-SQL Querying 读书笔记之查询优化
一. 自顶向下优化方法论 1. 分析实例级别的等待 在实例级找出什么类型的等待占用大部分的时间,通过sys.dm_os_wait_stats select wait_type, --等待类型 wait ...
- showModalDialog 超过问题
a.aspx页面打开一个弹出模式对话框b.aspx. a.aspx 页面页面代码: function SetPlay() { window.showModalDialog('SetAdvertisin ...
- iOS 获取手机的型号,系统版本,软件名称,软件版本
转载自:http://www.2cto.com/kf/201210/162333.html 网上搜索出来的,记录下来以后使用方便: [java]//手机序列号 NSString* ide ...
- 【BZOJ 1010】 [HNOI2008]玩具装箱toy
Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...
- C语言关键字-volatile
1.C语言关键字volatile C 语言关键字volatile(注意它是用来修饰变量而不是上面介绍的__volatile__)表明某个变量的值可能在外部被改变,因此对这些变量的存取 不能缓存 ...
- No qualifying bean of type [com.shyy.web.service.TreeMapper] found for dependency
异常信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sp ...
- Spring MVC控制层的返回类型--String类型与Bean类型
SpringMVC控制层的返回类型形式多样,现拿其中的两种--String类型与Bean类型作以说明. 一.测试项目的结构 说明:(jsp的名字没起好) 控制层:UserController.java ...