转自: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. final finally finalize 区别及用法

    final 1,final修饰的class,代表不可以继承扩展. 2.final的方法也是不可以重写的. 3.final修饰的变量是不可以修改的.这里所谓的不可修改对于基本类型来来,的确是不可以修改. ...

  2. spring配置文件加密

    原文:http://www.open-open.com/code/view/1453520072183 spring框架在一些对安全性要求较高的生产环境下,配置文件不允许出现明文用户名密码配置,如数据 ...

  3. HUNT:一款可提升漏洞扫描能力的BurpSuite漏洞扫描插件

    今天给大家介绍的是一款BurpSuite插件,这款插件名叫HUNT.它不仅可以识别指定漏洞类型的常见攻击参数,而且还可以在BurpSuite中组织测试方法. HUNT Scanner(hunt_sca ...

  4. BloomFilter学习

    看大数据面试题,看到BloomFilter,找了篇文章学习一下: http://www.cnblogs.com/heaad/archive/2011/01/02/1924195.html Bloom ...

  5. requests库帮助

    requests库帮助 http://docs.python-requests.org/zh_CN/latest/user/quickstart.html

  6. Rust 1.7.0 语法基础 sep_token 和 non_special_token

    一.分隔符 sep_token 指的是分隔符, 是除了 * 和 + 之外的不论什么符号,通常情况下是使用 , 逗号. 比如: 宏的多个參数分隔,以下代码中的逗号就是 sep_token (target ...

  7. Struts2框架起源

    曾经也用过S2SH框架做过几个项目,都不是工作中的,学习WEB开发的时候接触的第一套框架也是S2SH,可是工作之后一直没实用到S2SH 框架进行开发. 感觉曾经用这个框架的时候根本没有深入去了解这个框 ...

  8. LuaInterface简单介绍

    LuaInterface简单介绍 Lua是一种非常好的扩展性语言.Lua解释器被设计成一个非常easy嵌入到宿主程序的库.LuaInterface则用于实现Lua和CLR的混合编程. (一)Lua f ...

  9. [转] logback 常用配置详解(序)logback 简介

    转载文章:原文出处:http://aub.iteye.com/blog/1101222 logback 简介 Ceki Gülcü在Java日志领域世界知名.他创造了Log4J ,这个最早的Java日 ...

  10. 朴素的标题:MVC中权限管理实践

    基于MVC的web项目最好的权限控制方式我认为是对Action的控制,实现思路记录于此,权限管理分成两个部分授权.认证. 一.授权 1.读取当前项目中的所有需要控制的Action /// <su ...