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. Wpf 简单制作自己的窗体样式(2)

    上一篇blog讲了制作简单的样式的窗体,对于一个传统的窗体,不仅仅可以拖动,和关闭操作.还具有最大化.最小化.隐藏,以及改变窗体的大小等.这篇blog就是对上篇的补充,完善窗体的改变大小和最大化最小化 ...

  2. 【转】perl 变量 $/ 的用法解析 上下文为行模式时,$/ 定义以什么来区分行

    默认状态下,很显然都是用\n来区分行,\n也被我们称作为换行符. 当读取序列时,按行来读取时,就是以换行符为标准. 读取的strawberry1.gb的文件内容如下: LOCUS JX118024 4 ...

  3. Torry的困惑(基本型)

    #include<stdio.h> int main() { long long i,j; int n; //用于记录输入的要进行乘积的质数的个数 ; //用于记录前n个质数的乘积,并初始 ...

  4. iOS 本地存储四种方法

    在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题.将数据保存到本地,能够让程序的运行更加流畅,不会出现让人厌恶的菊花形状,使得用户体验更好.下面介绍⼀一下数据保存的方式: 1.NSKeye ...

  5. ios 8和iOS 9 适用的uidatepicker

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n ...

  6. Webstorm10.0.4注册码

    分享几个Webstorm10的注册码: (1) user name :EMBRACE ===== LICENSE BEGIN =====17739-1204201000002KkN!4z2O8JEyj ...

  7. 构建第一个Java程序

  8. PAT-乙级-1001. 害死人不偿命的(3n+1)猜想 (15)

    1001. 害死人不偿命的(3n+1)猜想 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Ca ...

  9. spoj 368

    额   最小生成树 ........ #include <cstdio> #include <cstring> #include <algorithm> using ...

  10. A JSTL primer, Part 2: Getting down to the core

    In the initial article of this series, you got your first look at JSTL. We described the use of its  ...