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. Winform 下拉框绑定问题

    在Winform中下拉框绑定的时候只能读到text属性值,Id的值不管怎么搞都读取不到,所以就百度找到了一种方式: public void CmdBind() { var data = _logic. ...

  2. WCF、Web API、WCF REST、Web Service之区别

    http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and-WCF-R ...

  3. sqlplus中"-S"和"-L"用法

    Usage: SQLPLUS [option] [logon] [start] <option> ::= -H | -V | [ [-L] [-M ] [-R ] [-S] ]   &qu ...

  4. ORA-27102: out of memory并伴随OSD-00031的处理

    刚才客户电话过来说有个数据库起不来了,开发商搞了好久搞不掂,得要让我们去帮忙看看.过去到现场,发现数据库无法打开,连nomount模式都不可以.报错的内容大致如下: ORA-27102: out of ...

  5. iOS开发学习路线图

    很多初学iOS开发的人会经常问:“我想学iOS应该从何入手呢?”.作为一个做了2年多各种iOS开发的程序员,只想写写自己的一些心得体会,好和体验与不好的体验.写的不好,请多包涵.希望能起到抛砖引玉的作 ...

  6. IOS开发之表视图添加索引

    我们要实现的效果如下. 1.修改ControlView.h,即添加变量dict,用于存储TabelView的数据源. #import <UIKit/UIKit.h> @interface  ...

  7. POJ 3701 概率DP

    给定2^n 支足球队进行比赛,n<=7. 队伍两两之间有一个获胜的概率,求每一个队伍赢得最后比赛的概率是多少? 状态其实都是很显然的,一开始觉得这个问题很难啊,不会.dp[i][j] 表示第i支 ...

  8. (转载)Cocos2dx-OpenGL ES 2.0教程:你的第一个三角形(1)

    前言 在本系列教程中,我会以当下最流行的2D引擎Cocos2D-X为基础,介绍OpenGL ES 2.0的一些基本用法.本系列教程的宗旨是OpenGL扫盲,让大家在使用Cocos2D-X过程中,知其然 ...

  9. MyBatis对不同数据库的主键生成策略

    本文转自:http://289972458.iteye.com/blog/1001851  http://hi.baidu.com/zim_it/blog/item/8a2bd11205f5b56ec ...

  10. Hadoop1.0.3集成eclipse开发

    本文来自:http://www.ilablog.org/%E7%BC%96%E8%AF%91hadoop-eclipse%E6%8F%92%E4%BB%B6/ 本人由于工作原因目前没有亲自尝试,那位尝 ...