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. SystemInfo获取计算机相关信息

    // SystemInfo.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include <iostream>#include ...

  2. LinkedStack<T>

    public class LinkedStack<T> { private static class Node<U> { U item; Node<U> next; ...

  3. mongodb添加延时节点

    1.      简介 延时节点是主节点过去某个时间点的“数据快照”,通常用来做数据备份,如果主节点有误操作而删除了数据,可以通过延时节点来恢复数据.例如,当前时间是10:00,并且延时节点设置1个小时 ...

  4. FMX StringGrid向上滑动自动加载记录(一)

    有时候,做的app还是需要用StringGrid来显示数据,但如果用StringGrid的Livebinding绑定到一个数据集TDataset,当记录超过1000条时,效率非常低,甚至达不到实用状态 ...

  5. Emacs矩形操作

    原始矩形块模式 emacs以C-x r开头的命令来进行矩形操作.先用C-space或者C-@设一个mark,移动光标到另一点,用以下命令进行列操作: C-x r r 复制一个矩形区域到寄存器 C-x ...

  6. IDC:2014年的十大 IT 趋势

    IDC:2014年的十大 IT 趋势 市场研究公司 IDC 近日发布报告,对 2014 年的十大科技行业发展趋势作出了预测.IDC 称,2014 年将是科技业"鏖战正酣"的一年,整 ...

  7. JSP--TOMCAT-MYSQL web页面查询

    queryStudent.jsp代码如下 <%@ page language="java" contentType="text/html; charset=gb23 ...

  8. MyEclipse10下创建web项目并发布到Tomcat

    MyEclipse10下创建web项目并发布到Tomcat 1.软件安装(不作详细描述) 2.启动MyEclipse10 3.File-New-Project,选中Web Project,点击Next ...

  9. web 资源好文

    https://www.jianshu.com/p/e065aadf8daa : 五年 Web 开发者 star 的 github 整理说明

  10. Python之进程(multiprocessing)

    一.multiprocessing模块简介——进程基于“threading”的接口 multiprocessing模块支持创建进程——使用threading模块相似的API.multiprocessi ...