Six Degrees of Cowvin Bacon

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 2   Accepted Submission(s) : 1
Problem Description
The cows have been making movies lately, so they are ready to play a variant of the famous game "Six Degrees of Kevin Bacon".

The game works like this: each cow is considered to be zero degrees of
separation (degrees) away from herself. If two distinct cows have been in a
movie together, each is considered to be one 'degree' away from the other. If a
two cows have never worked together but have both worked with a third cow, they
are considered to be two 'degrees' away from each other (counted as: one degree
to the cow they've worked with and one more to the other cow). This scales to
the general case.

The N (2 <= N <= 300) cows are interested in
figuring out which cow has the smallest average degree of separation from all
the other cows. excluding herself of course. The cows have made M (1 <= M
<= 10000) movies and it is guaranteed that some relationship path exists
between every pair of cows.

 
Input
* Line 1: Two space-separated integers: N and M
<br> <br>* Lines 2..M+1: Each input line contains a set of two or
more space-separated integers that describes the cows appearing in a single
movie. The first integer is the number of cows participating in the described
movie, (e.g., Mi); the subsequent Mi integers tell which cows were.
<br>
 
Output
* Line 1: A single integer that is 100 times the
shortest mean degree of separation of any of the cows. <br>
 
Sample Input
4 2
3 1 2 3
2 3 4
 
Sample Output
100
 
 #include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#define inf 0x3f3f3f3f
using namespace std;
int e[][];
int n, m;
int main()
{
int n, m;
cin >> n >> m;
int i, j;
int a[];
for (i = ; i <= n; i++)
{
for (j = ; j <= n; j++)
{
if (i == j) e[i][j] = ;
else e[i][j] = inf;
}
}
for (i = ; i <= m; i++)
{
int k,p;
cin >> k;
for (j = ; j <= k; j++)
{
cin >> a[j];
}
for (j = ; j <= k; j++)
{
for (p = j+; p <= k; p++)
{
e[a[j]][a[p]] = ;
e[a[p]][a[j]] = ;
}
}
}
int k;
for (k = ; k <= n; k++)
{
for (i = ; i <= n; i++)
{
for (j = ; j <= n; j++)
{
if (e[i][j] > e[i][k] + e[k][j])
e[i][j] = e[i][k] + e[k][j];
}
}
}
int ans = inf;
int sum = ;
for (i = ; i <= n; i++)
{
sum = ;
for (j = ; j <= n; j++)
{
if (e[i][j] != inf)
{
sum += e[i][j];
}
}
if (sum < ans) ans = sum;
}
ans= ans*/ (n-) ;
cout <<ans<< endl;
}

POJ 2139 Six Degrees of Cowvin Bacon (floyd)的更多相关文章

  1. AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...

  2. <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 ...

  3. POJ 2139 Six Degrees of Cowvin Bacon (Floyd)

    题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...

  4. 任意两点间最短距离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 ...

  5. POJ 2139 Six Degrees of Cowvin Bacon

    水题,Floyd. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...

  6. POJ 2139 Six Degrees of Cowvin Bacon (弗洛伊德最短路)

    题意:奶牛拍电影,如果2个奶牛在同一场电影里演出,她们的合作度是1,如果ab合作,bc合作,ac的合作度为2,问哪一头牛到其他牛的合作度平均值最小再乘100 思路:floyd模板题 #include& ...

  7. POJ:2139-Six Degrees of Cowvin Bacon

    传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...

  8. POJ2139 Six Degrees of Cowvin Bacon [Floyd]

    水题,随手敲过 一看就是最短路问题,a,b演同一场电影则他们的距离为1 默认全部两两原始距离无穷,到自身为0 输入全部数据处理后floyd 然后照它说的求平均分离度 再找最小的,×100取整输出 #i ...

  9. 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)

    Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...

随机推荐

  1. Windows8连接网络后自动弹出Bing解决方法

    Windows8 网络连接速度很快( ADSL ),但是连接之后总是会打开 Bing,这是很烦人的一件事,因为你连接网络可能并不想打开浏览器,甚至,你讨厌 Bing. 我也一直被这个问题困扰了很久,用 ...

  2. jquery 实现内容的级联选取

  3. 玩转树莓派:OpenHAB的入门(二)

    通过第一篇的介绍,我们现在已经安装了OpenHAB和Demo House,那么接下来我们来看一下OpenHAB是如何工作的. OpenHAB如何工作? 接下来你会在openHAB配置的共享文件夹看到s ...

  4. Qt 获取组合键 键盘按住某键 鼠标组合实现

    #include "mainwindow.h" #include <QDebug> #include <QKeyEvent> #include <QM ...

  5. OpenCV代码提取:遍历指定目录下指定文件的实现

    前言 OpenCV 3.1之前的版本,在contrib目录下有提供遍历文件的函数,用起来比较方便.但是在最新的OpenCV 3.1版本给去除掉了.为了以后使用方便,这里将OpenCV 2.4.9中相关 ...

  6. 从 0 到 1 合理高效使用 GitHub 的资料

    来自:https://github.com/xirong/my-git/blob/master/how-to-use-github.md 说明 作为一名开发者,Github上面有很多东西值得关注学习, ...

  7. 在Windows XP系统下架设FTP服务器需要5个步骤。

    4步win7下简单FTP服务器搭建:http://blog.sina.com.cn/s/blog_3f7e47f20100haur.html 申请网域护照(即帐户),开通免费域名.连接到www.ora ...

  8. Unity 3D编辑器扩展介绍、教程(二) —— 创建窗口

    Unity编辑器扩展教程(二) 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 一 Brief Introd ...

  9. php MySQL()函数

    1.mysql_query() 函数执行一条 MySQL 查询:mysql_query(query,connection) 2.mysql_fetch_array() 函数 3.mysql_fetch ...

  10. linux搜索命令之find和grep

    在使用linux时,经常需要进行文件查找,其中查找的命令主要有find和grep.两个命令是有区的. 区别:(1)find命令是根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为空,访 ...