转自:https://blog.csdn.net/a17865569022/article/details/78766867

Input
* Line 1: Two space-separated integers: N and M 
* 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. 
Output
* Line 1: A single integer that is 100 times the shortest mean degree of separation of any of the cows.

Sample Input
4 2
3 1 2 3
2 3 4
Sample Output
100

Hint
[Cow 3 has worked with all the other cows and thus has degrees of separation: 1, 1, and 1 -- a mean of 1.00 .]

思路:最短路问题。

在建图的时候要注意将对角线一列设为0,其余在初始状态下设为INF无穷大

然后将在一个集合的元素之间的距离设为1(这里的图为对称矩阵!!)

之后再用Floyd算法更新间接有关系的坐标Map[i][j]=min(Map[i][j],Map[i][k]+Map[k][j]);

最后输出Min*100/(n-1)(这里注意,一定要先乘100,再去取平均,int的数不能整除的话会舍去小数点后面的数,导致结果扩大100倍后误差较大!!!)

#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 99999999
using namespace std;
int main()
{
int n,m,t,a[];
int Map[][];
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
{
Map[i][i]=;
for(int j=i+;j<=n;j++)
Map[i][j]=Map[j][i]=INF;
}
for(int i=;i<=m;i++)
{
scanf("%d",&t);
for(int j=;j<=t;j++)
scanf("%d",&a[j]);
for(int x=;x<=t;x++)
for(int y=x+;y<=t;y++)
Map[a[x]][a[y]]=Map[a[y]][a[x]]=;
}
for(int k=;k<=n;k++)//Floyd算法
{
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]);
}
}
}
/*for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
printf("%10d",Map[i][j]);
printf("\n");
}*/
int Min=INF,temp;
for(int i=;i<=n;i++)
{
temp=;
for(int j=;j<=n;j++)
temp+=Map[i][j];
if(temp<Min)
Min=temp;
}
printf("%d\n",Min*/(n-));//重要点,先乘后除,防止误差过大
return ;
}

Six degrees of Kevin Bacon的更多相关文章

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

  2. POJ2139--Six Degrees of Cowvin Bacon(最简单Floyd)

    The cows have been making movies lately, so they are ready to play a variant of the famous game &quo ...

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

    Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Ja ...

  4. POJ:2139-Six Degrees of Cowvin Bacon

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

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

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

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

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

  7. ShortestPath:Six Degrees of Cowvin Bacon(POJ 2139)

    牛与电影 题目大意:就是一群牛,又在玩游戏了(怎么你们经常玩游戏),这个游戏规则如下,把牛拆分成一个一个组,并且定义一个“度”,规定在一个组的牛与他自己的度为0,与其他牛的度为1,不同组的牛不存在度, ...

  8. POJ 2139 Six Degrees of Cowvin Bacon

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

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

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

随机推荐

  1. Distinct Subsequences (dp)

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  2. 从CLR GC到CoreCLR GC看.NET Core对云原生的支持

    内存分配概要 前段时间在园子里看到有人提到了GC学习的重要性,很赞同他的观点.充分了解GC可以帮助我们更好的认识.NET的设计以及为何在云原生开发中.NET Core会占有更大的优势,这也是一个程序员 ...

  3. curl -L 跟随跳转

    curl -L 跟随跳转 加上-v 就可以看见详细信息: 学习了:https://www.cnblogs.com/davicelee/archive/2011/11/19/cURL.html http ...

  4. Unity 3D 中动态字体的创建

    原创不易,转载请注明转自: http://blog.csdn.net/u012413679/article/details/26232453 ---- kosion 1.载入NGUI插件包,载入完毕后 ...

  5. 【Mongodb教程 第一课 补加课】 Failed to connect to 127.0.0.1:27017, reason: errno:10061 由于目标计算机积极拒绝,无法连接

    1:启动MongoDB 2014-07-25T11:00:48.634+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errn ...

  6. 2016/2/25 onchange 应用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. getHibernateTemplate()(Spring中常用的hql查询方法)

    Spring中常用的hql查询方法(getHibernateTemplate()) --------------------------------- 一.find(String queryStrin ...

  8. mysql 5.5安装不对容易出现问题

    按照正常步骤安装完了mysql 5.5之后,再运行一下bin目录中的mysqlinstanceconfig.exe,重置一下密码!!!! 重置密码的地方:modify security setting ...

  9. C++ 函数部分(2)

    C++函数的递归调用 函数可以直接或间接地调用自身,称为递归调用.所谓直接调用自身,就是指在一个函数的函数体中出现了对自身的调用表达式,例如: void fun1(void) { //do somet ...

  10. Docker vs. Kubernetes vs. Apache Mesos: Why What You Think You Know is Probably Wrong

    Docker vs. Kubernetes vs. Apache Mesos: Why What You Think You Know is Probably Wrong - Mesosphere h ...