Six degrees of Kevin Bacon
转自: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的更多相关文章
- <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 ...
- 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 ...
- POJ 2139 Six Degrees of Cowvin Bacon (floyd)
Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Ja ...
- POJ:2139-Six Degrees of Cowvin Bacon
传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...
- AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...
- 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)
Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
- ShortestPath:Six Degrees of Cowvin Bacon(POJ 2139)
牛与电影 题目大意:就是一群牛,又在玩游戏了(怎么你们经常玩游戏),这个游戏规则如下,把牛拆分成一个一个组,并且定义一个“度”,规定在一个组的牛与他自己的度为0,与其他牛的度为1,不同组的牛不存在度, ...
- POJ 2139 Six Degrees of Cowvin Bacon
水题,Floyd. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...
- POJ 2139 Six Degrees of Cowvin Bacon (Floyd)
题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...
随机推荐
- eclipse提速02 - eclipse.ini优化
给eclipse执行jvm.它可以让你使用自己的jdk,而不是系统环境变量所指定的jdk -vm /path/to/your/java 使用最新的jdk来运行eclipse.使用最新的jdk要好很多. ...
- 系统性能不够原因可能是cpu不够,内存不够等等
1.Linux系统可以通过top命令查看系统的CPU.内存.运行时间.交换分区.执行的线程等信息. 通过top命令可以有效的发现系统的缺陷出在哪里.是内存不够.CPU处理能力不够.IO读写过高. 2. ...
- 关于maven的规则插件:Maven Enforcer plugin
Maven提供了Maven-Enforcer-Plugin插件,用来校验约定遵守情况(或者说校验开发环境).比如JDK的版本,Maven的版本,开发环境(Linux,Windows等),依赖jar包的 ...
- Robocopy进行大量迁移
建议使用 Windows Server 2012 R2 或 Windows Server 2012 随附的 Robocopy.exe 版本. 即然官方建议我们用2012或2012R2所带的Roboco ...
- [RxJS] Implement RxJS `switchMap` by Canceling Inner Subscriptions as Values are Passed Through
switchMap is mergeMap that checks for an "inner" subscription. If the "inner" su ...
- 使用MySQL Workbench进行数据库设计——MySQL Workbench用法总结
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/48318877 本文出自[我是干勾鱼的博客] 1 简单介绍 MySQL Workb ...
- 广东IP段列表
广东IP段列表219.137.240.0 219.137.240.255219.137.148.0 219.137.150.255 广东省广州市 电信ADSL219.137.144.0 219.137 ...
- Spring3+ibatis (SQL Server)+pager-taglib.tld查询分页的实现
pager-taglib分页開始~ 查了好多关于分页的技术,终于选定下面方法实现~ 1.首先下载jar包:pager-taglib.jar,pager-taglib.jar放在WEB-INF/lib文 ...
- eclipse中经常使用快捷键
熟练一些快捷键,会使你的开发更加快捷.高效,值得花些时间学一下! 1. ctrl+shift+r:打开资源 这可能是全部快捷键组合中最省时间的了.这组快捷键能够让你打开你的工作区中不论什么一个文件,而 ...
- 搭建nodejs服务,访问本地站点文件
搭建nodejs服务器步骤: 1.安装nodejs服务(从官网下载安装) 2.在自己定义的目录下新建服务器文件如 server.js 例如,我在E:\PhpProject\html5\websocke ...