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. Pycharm(二)创建项目

    首次打开就是这样,可以创建新项目,打开一个项目,也可以从版本控制打开项目 我们就新建项目吧,Create New Project 创建项目就是这样了 Location:项目路径. Interprete ...

  2. 判断当前应用程序处于前台还是后台 ANDROID

    /**     *判断当前应用程序处于前台还是后台     *      * @param context * @return         */    public static boolean ...

  3. tomcat用户配置,内存配置,pid配置

    一:tomcat用户配置 1.打开 webapps\manager\WEB-INF\web.xml 可以看到tomcat所有的角色名,后面我们就是需要配置这些角色 2.给用户添加角色 打开 conf/ ...

  4. 2018-2019-2 网络对抗技术 20165202 Exp2 后门原理与实践

    博客目录 一.基础问题回答 二.实验准备:后门软件 1.Windows获得Linux Shell 2.Linux获得Windows Shell 3.使用nc传输数据 4.使用ncat实现文件传输 三. ...

  5. 写在连载之前——DIY微型操作系统篇

    这个博客开了这么久都没写过什么东西.可能是因为我想写的东西在网上都能找得到,所以自己也懒得去写了. 但是这次当我在看<30天自制操作系统>这本书的时候发现,如果不用作者原版的光盘软件,要自 ...

  6. clipboard.js 实现web端---> 复制到剪切板功能

    package.json 中: 添加clipboard 依赖 "dependencies": { "vue": "^2.2.2", &quo ...

  7. 微信小程序插件使用

    使用插件 小程序开发者可便捷地把插件添加到自己的小程序内,丰富小程序的服务.当用户在使用小程序时,将可以在小程序内使用插件提供的服务. 开放范围 所有小程序 接入流程 在小程序管理后台添加插件 小程序 ...

  8. magento增加左侧导航栏

    1.打开 app\design\frontend\default\modern\layout\catalog.xml,在适当位置加入以下代码: <reference name=”left”> ...

  9. Samsung_tiny4412(驱动笔记07)----spinlock,semaphore,atomic,mutex,completion,interrupt

    /*********************************************************************************** * * spinlock,se ...

  10. SendTo MD5 - imsoft.cnblogs

    SendTo MD5 is a small application that allows you to calculate and compare MD5 checksums of files an ...