1837

被数据结构部分打击的不行了 换地 刷点简单的 图论第一题 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)的更多相关文章

  1. ural 1837 Isenbaev's Number

    http://acm.timus.ru/problem.aspx?space=1&num=1837 #include <cstdio> #include <cstring&g ...

  2. ural 1837. Isenbaev's Number bfs

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1837 描述: Isenbaev是国外的一个大牛. 现在有许多人要参加ACM ICPC. ...

  3. URAL 1837. Isenbaev&#39;s Number (map + Dijkstra || BFS)

    1837. Isenbaev's Number Time limit: 0.5 second Memory limit: 64 MB Vladislav Isenbaev is a two-time ...

  4. [LeetCode] 287. Find the Duplicate Number(Floyd判圈算法)

    传送门 Description Given an array nums containing n + 1 integers where each integer is between 1 and n  ...

  5. 图论-最短路径 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). ...

  6. floyd算法学习笔记

    算法思路 路径矩阵 通过一个图的权值矩阵求出它的每两点间的最短路径矩阵.从图的带权邻接矩阵A=[a(i,j)] n×n开始,递归地进行n次更新,即由矩阵D(0)=A,按一个公式,构造出矩阵D(1):又 ...

  7. UVA10048 Audiophobia[Floyd变形]

    UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...

  8. Find the Duplicate Number

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  9. ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩

    HDU 5418 Victor and World Time Limit:2000MS     Memory Limit:131072KB     64bit IO Format:%I64d & ...

随机推荐

  1. 使用CSS修改HTML5 input placeholder颜色( 转载 )

    问题:Chrome支持input=[type=text]占位文本属性,但下列CSS样式却不起作用: input[placeholder], [placeholder], *[placeholder] ...

  2. nodejs npm install全局安装和本地安装的区别

    npm的包安装分为本地安装(local).全局安装(global)两种,从敲的命令行来看,差别只是有没有-g而已,比如:代码如下:复制代码npm install # 本地安装npm install - ...

  3. 使用GruntJS构建Web程序

    Gruntjs是JavaScript项目的构建工具,也是基于node的一个命令行工具.很多开源JS项目都是使用它搭建.如jQuery.Qunit.CanJS等.它有以下作用 合并JS文件 压缩JS文件 ...

  4. php连接ftp

    PHP连接ftp,发现一个很好用的类库phpseclib.英文原文 Connecting to SFTP with PHP If you need to connect to SFTP using P ...

  5. 拓展,Fibonacci螺旋

    #该程序由023递归这课中的fibonacci数列递归写法修改而成 #在写的过程中发现,如果要正确引导用户的每一次输入,写的代码比主程序还要多 #当然,为了使程序在用户交互过程中显得更加友好,提供错误 ...

  6. insert into (select...WITH CHECK OPTION) values(...)

    insert into (<subquery> WITH CHECK OPTION) values (...) 语法看起来很特殊,其实是insert进subquery的这张表里: 1. 只 ...

  7. 解决rhel相关系统下yum找不到安装包的解决方法

    最近重新安装了Linux,用的版本是CentOS 5.1.但老是出现很多包找不到的情况. [root@toughhou /]# yum install rlwrap Loaded plugins: f ...

  8. Oracle表连接

    一个普通的语句select * from t1, t2 where t1.id = t2.id and t1.name = 'a'; 这个语句在什么情况下最高效? 表连接分类: 1. 嵌套循环连接(N ...

  9. SPFA&邻接表 PASCAL

    题目来自CODE[VS]-->热浪 1557 热浪 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石       题目描述 Description 德克萨斯纯朴的民眾们这个 ...

  10. 搭建Git Server

    windows上如何搭建Git Server   Git在版本控制方面,相比与SVN有更多的灵活性,对于开源的项目,我们可以托管到Github上面,非常方便,但是闭源的项目就会收取昂贵的费用.那么私有 ...