POJ-2139 Six Degrees of Cowvin Bacon---Floyd
题目链接:
https://vjudge.net/problem/POJ-2139
题目大意:
给定一些牛的关系,他们之间的距离为1。
然后求当前这只牛到每只牛的最短路的和,除以 n - 1只牛的最大值。(这里直接取整就行啦)
思路:
floyd来求最短路。
然后枚举求max就行了。
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
using namespace std;
typedef pair<int, int> Pair;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int T, n, m;
const int maxn = 2e4 + ;
int Map[][];
int x[];
ll sum[];
void floyd()
{
for(int k = ; k <= n; k++)
{
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
Map[i][j] = min(Map[i][j], Map[i][k] + Map[k][j]);
}
}
}
ll sum, minn = INF;
for(int i = ; i <= n; i++)
{
sum = ;
for(int j = ; j <= n; j++)
sum += (ll)Map[i][j];
minn = min(minn, sum);
}
int ans = minn * / (n - );
cout<<ans<<endl;
}
int main()
{
cin >> n >> m;
memset(Map, INF, sizeof(Map));
for(int i = ; i <= n; i++)Map[i][i] = ;
while(m--)
{
int t;
cin >> t;
for(int i = ; i < t; i++)cin >> x[i];
for(int i = ; i < t; i++)
for(int j = i + ; j < t; j++)
Map[x[i]][x[j]] = Map[x[j]][x[i]] = ; }
floyd();
}
POJ-2139 Six Degrees of Cowvin Bacon---Floyd的更多相关文章
- POJ 2139 Six Degrees of Cowvin Bacon (floyd)
Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Ja ...
- AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...
- <poj - 2139> Six Degrees of Cowvin Bacon 最短路径问题 the cow have been making movies
本题链接:http://poj.org/problem?id=2139 Description: The cows have been making movies lately, so the ...
- POJ 2139 Six Degrees of Cowvin Bacon (Floyd)
题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...
- 任意两点间最短距离floyd-warshall ---- POJ 2139 Six Degrees of Cowvin Bacon
floyd-warshall算法 通过dp思想 求任意两点之间最短距离 重复利用数组实现方式dist[i][j] i - j的最短距离 for(int k = 1; k <= N; k++) f ...
- POJ 2139 Six Degrees of Cowvin Bacon
水题,Floyd. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...
- POJ 2139 Six Degrees of Cowvin Bacon (弗洛伊德最短路)
题意:奶牛拍电影,如果2个奶牛在同一场电影里演出,她们的合作度是1,如果ab合作,bc合作,ac的合作度为2,问哪一头牛到其他牛的合作度平均值最小再乘100 思路:floyd模板题 #include& ...
- POJ:2139-Six Degrees of Cowvin Bacon
传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...
- POJ2139 Six Degrees of Cowvin Bacon [Floyd]
水题,随手敲过 一看就是最短路问题,a,b演同一场电影则他们的距离为1 默认全部两两原始距离无穷,到自身为0 输入全部数据处理后floyd 然后照它说的求平均分离度 再找最小的,×100取整输出 #i ...
- 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)
Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
随机推荐
- 浅谈ORM操作
2. ORM(对象关系映射) 1. 映射的关系 DB ORM 数据表 <--> 类 数据行 <--> 对象 字段 <--> 属性 2. Django项目使用MySQ ...
- 增加tomcat多实例
第一步:解压 第二步:修改端口 /data/service/tomcat1/conf <Server port="8006" shutdown="SHUTDOWN& ...
- java——java只有值传递
真的只有值传递! java中对象作为参数传递给一个方法,到底是值传递,还是引用传递? 答:值传递 这里说的很清楚了:https://www.cnblogs.com/zhouxiansheng/p/39 ...
- 文献综述一:基于UML技术的商品管理系统设计与实现
一.基本信息 标题:基于UML技术的商品管理系统设计与实现 时间:2018 出版源:福建电脑 文件分类:uml技术的研究 二.研究背景 使用 UML 技术对商品管理系统进行了分析与研究,使用户对商品信 ...
- 数据结构---Java---数组
**************************************************************前言************************************ ...
- C# 连接 Exchange 发送邮件
C#连接Exchange 发送邮件代码如下 /// <summary> /// exchange群发邮件 /// </summary> /// <param name=& ...
- RNN学习资料
1. Recurrent Neural Networks Tutorial, Part 2 – Implementing a RNN with Python, Numpy and Theano htt ...
- [转]how can I change default errormessage for invalid price
本文转自:http://forums.asp.net/t/1598262.aspx?how+can+I+change+default+errormessage+for+invalid+price I ...
- PHP设计原则
Laravel PHP设计模式 定义:将PHP设计成一个固化的模式 面向对象设计原则 内聚度:高内聚,表示一个应用程序的单个单元所负责的任务数量和多样性.内聚与单个类或者单个方法单元相关 耦合度: ...
- C# 和 Linux 时间戳转换
/// <summary> /// 时间戳转为C#格式时间 /// </summary> /// <par ...