转自: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. Eclipse 中 新建maven项目 无法添加src/main/java 问题

    eclipse创建maven web项目,在选择maven_archetype_web原型后,默认只有src/main/resources这个Source Floder. 按照maven目录结构,添加 ...

  2. memcached源代码分析-----set命令处理流程

    转载请注明出处:http://blog.csdn.net/luotuo44/article/details/44236591 前一篇博文以get命令为样例把整个处理流程简单讲述了一遍.本篇博文将以se ...

  3. simple-todo: 一个简易的 todo 程序 - django版

    今天无意间看到  simple-todo: 一个简易的 todo 程序 - web.py 中文教程 ,然后发现竟然有好多的版本 http://simple-is-better.com/news/tag ...

  4. Linux如何更新软件源

    Linux软件源的设置方法 1 打开数据源配置文件 vi /etc/apt/sources.list     添加相关的数据源,可以选择以下的数据源,不要写太多,否则会影响更新速度.   之后使用ap ...

  5. 熊猫猪新系统測试之二:Mac OS X 10.10 优胜美地

    在第一篇windows 10技术预览版測试之后.本猫为大家呈现还有一个刚刚才更新的mac操作系统:"优胜美地".苹果相同一改以猫科动物为代号命名的传统.在10.9的Maverick ...

  6. 微信小程序实战之 goods(订餐页)

    项目目录: 模拟数据: utils / data.js function getSData() { var data = [ { "name": "热销榜", ...

  7. 【Mongodb教程 第十二课 】PHP mongodb 的使用

    mongodb 不用过多的介绍了,NOSQL的一种,是一个面向文档的数据库,以其方便灵活的数据结构,对于开发者来说是比较友好的,同时查询的速度也是比较快的,现在好多网站 开始使用mongodb ,具体 ...

  8. Use Local Or Global Index?

    常常我们须要将大表依据分区键进行分区,当建立索引的时候.我们究竟使用local 还是global 索引呢 先看看两种索引的特点: 本地索引特点: 1. 本地索引一定是分区索引.分区键等同于表的分区键. ...

  9. 使用JDBC 插入向数据库插入对象

    package com.ctl.util; import java.io.IOException; import java.lang.reflect.Field; import java.lang.r ...

  10. 【iOS系列】-触摸事件与手势识别

    [iOS系列]-触摸事件与手势识别 第一:触摸事件 一根手指触摸屏幕时,会创建一个与手指相关联的UITouch对象 UIEvent:称为事件对象,记录事件产生的时刻和类型 两根手指同时触摸一个view ...