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忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
随机推荐
- jenkins出现的问题
1.增加服务器时 要修改时,,需要设置 2:出现这个问题是 执行了npm install node-sass
- python 格式化时间含中文报错: 'locale' codec can't encode character '\u5e74'
执行下面代码报错: UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: Illegal ...
- ubuntu14.04&matlab2015b 测试caffe的Matlab接口
Step1: 修改caffe-master中的Makefile.config 提示:可以到文件中直接“ctrl+f”,键入相应大写字母即可查找到相应位置. Step2:编译接口.如果之前编译caffe ...
- linux 命令(Ubuntu)
1. 我们可以使用下列的命令压缩一个目录: # zip -r archive_name.zip directory_to_compress 2. 下面是如果解压一个zip文档: # unzip arc ...
- Android中的AlertDialog遇到的错误
public void showAddIPCDialog() { Log.i("ssssssssss","wwwwwwwwww"); LayoutInflate ...
- inventor安装失败怎样卸载安装inventor 2019?
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- [转]js 判断js函数、变量是否存在
本文转自:http://blog.csdn.net/liang4571231/article/details/4042519 在进行js编程时,总会出现可能一些函数或者变量未定义而被引用,导致报错的情 ...
- thinkphp3.2 删除Runtime目录里的缓存文件,标记一下,以下好找。
操作如下: utility::clearCache("Data"); 或 utility::clearCache("Data-Logs"); class uti ...
- Kudu的配置(官网推荐的步骤)(Configuring Apache Kudu)
不多说,直接上干货! http://kudu.apache.org/docs/configuration.html
- 百度网页分享js代码
1.小图标 <div class="bdsharebuttonbox"> <a href="#" class="bds_qzone& ...