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. GridView - javascript 触发后台 OnSelectedIndexChanged

    1.ASPX <asp:GridView ID="gdvDealers" runat="server" AutoGenerateColumns=" ...

  2. PHP服务器负载判断

    <?php header("content-type:text/html;charset=utf-8"); // echo PHP_OS;exit; // echo get_ ...

  3. python staticmethod classmethod

    http://www.cnblogs.com/chenzehe/archive/2010/09/01/1814639.html classmethod:类方法staticmethod:静态方法 在py ...

  4. python学习之html从0开始(一)

    <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...

  5. linux C语言getopt()函数的使用

    getopt被用来解析命令行选项参数. #include <unistd.h> 函数及参数介绍 extern char *optarg; //选项的参数指针,如果选项字符串里的字母后接着冒 ...

  6. hdu 4641 K-string SAM的O(n^2)算法 以及 SAM+并查集优化

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4641 题意:有一个长度为n(n < 5e4)的字符串,Q(Q<=2e5)次操作:操作分为:在末 ...

  7. OFBiz进阶之HelloWorld(五)创建新实体

    参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guid ...

  8. Oracle “CONNECT BY” 使用

    Oracle “CONNECT BY” 使用 功能说明: 语法结构如下: [ START WITH condition ] CONNECT BY [ NOCYCLE ] condition 说明: 1 ...

  9. 移动端webapp开发必备知识

    移动设备的用户越来越多,每天android手机的激活量都已经超过130万台,所以我们面向移动终端的WebAPP也开始跟进了.本文主要介绍webapp的开发与调试的相关知识和经验,以及给出几种可选的解决 ...

  10. EXTJS4.2 时间动态刷新显示

    function clockGo() { Ext.TaskManager.start({ run: function () { //Ext.getCmp("clock").setT ...