本题链接http://poj.org/problem?id=2139

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

* 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 .] 

 题意:有一群牛在拍电影(牛们的生活真丰富),如果两头牛在同一部电影中出现过,那么这两头牛的度就为1,如果a与b之间有n头媒介牛,那么a,b的度为n+1。 给出m部电影,每一部给出牛的个数和编号。问哪一头到其他每头牛的度数平均值最小,输出 最小 平均值 乘100。

 解题思路:只要把任意两个牛之间的最小度求出来然后就处理就行了,可以考虑用Floyd算法(三个for

 参考代码:

 #include <cstring>
#include <iostream>
#define INF 9999999
#define maxn 300
using namespace std; int cost[maxn][maxn];
int p[maxn];
int V; void fl () {
for (int k = ; k <= V; ++k) {
for (int i = ; i <= V; ++i) {
for (int j = ; j <= V; ++j) {
cost[i][j] = min (cost[i][j], cost[i][k] + cost[k][j]);
}
}
}
} int main () {
int x, y;
int a, b;
int n; cin >> V >> n; //-----------------------------------------初始化
memset (p, , sizeof(p));
for (int i = ;i <= V; ++i)
for (int j = ; j <= V; ++j)
cost[i][j] = INF;
for (int i = ; i <= V; ++i)
cost[i][i] = ;
//-----------------------------------------整理输入数据 while (n--) {
cin >> y;
for (int i = ; i <= y; ++i) {
cin >> p[i];
}
for (int i = ;i <= y; ++i) {
for (int j = i + ; j <= y; ++j) {
a = p[i];
b = p[j];
cost[b][a] = cost[a][b] = ;///a和b之间的距离
}
}
} fl ();//--------------调用函数 //-------------------------------------------------------求最小值输出
int sum, minsum = INF;
int i, j; for (i = ; i <= V; ++i) {
sum = ;
for (j = ; j <= V; ++j) {
sum += cost[i][j];
}
if (sum < minsum)//求最小值
minsum = sum;
} cout << (minsum * ) / (V - ) << endl; //输出 最小 平均值 return ;
}

  欢迎码友评论,一起成长。

<poj - 2139> Six Degrees of Cowvin Bacon 最短路径问题 the cow have been making movies的更多相关文章

  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 (floyd)

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

  3. 任意两点间最短距离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 ...

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

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

  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. 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)

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

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

随机推荐

  1. const与readonly的区别

    const与readonly 很像,都是将变量声明为只读,且在变量初始化后就不可改写.那么,const与readonly 这两个修饰符到底区别在什么地方呢?其实,这个牵扯出C#语言中两种不同的常量类型 ...

  2. 应该熟知的表单js应用(select、label、submit)

    前言  首先需要清楚的是,表单传数据方式,有POST和GET的方式,通过name和对应的value值提交到后台.通过name,可以用对象属性调用的方式获取对应的input标签,如: document. ...

  3. Media Formatters媒体格式化器

    Media Formatters媒体格式化器 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyok/p/344 ...

  4. C#使用文件监控对象FileSystemWatcher 实现数据同步

    在C#使用文件监控对象FileSystemWatcher 实现数据同步 2013-12-12 18:24 by 幕三少, 352 阅读, 3 评论, 收藏, 编辑 最近在项目中有这么个需求,就是得去实 ...

  5. Best Cow Line(POJ No.3617)

    问题: 链接:http://poj.org/problem?id=3617 思路: 按照字典序比较S和将S反转后的字符串S' 如果S较小,就从S的开头取出一个字符,加到T的末尾(更新下标值) 如果S’ ...

  6. DevExpress 学习使用之 SplitContainerControl

    无论是 .net framework 自带还是第三方组件,使用 Split 类控件时通常其 Panel 中都会包含多个子控件,在运行时不可避免遇到因改变 splitter 位置或改变窗体大小引起的界面 ...

  7. 基于Redis的CustomerSessionProvider(二)

    接一的考虑,那么就做Redis的SessionProvider就非常简单了,只考虑整个Session的缓存,主要实现以下两个函数就可以了 public override SessionStateSto ...

  8. asp.net内部原理3

    asp.net内部原理(三) 第三个版本 (最详细的版本) 前言: 今天继续吧这个系列补齐,这几天公司的项目比较忙,回到家已经非常的累了,所以也没顾得上天天来这里分享一些东西和大家一起探讨,但是今天晚 ...

  9. PDF.NET开发框架性能剖析

    PDF.NET开发框架性能剖析 前俩天发布了 关于PDF.NET开发框架对Mysql Sqlite PostgreSQL数据库分页支持的个人看法 ,说明了本人对框架的一些介绍和看法.今天我们一起思考一 ...

  10. 设计师和开发人员更快完成工作需求的20个惊人的jqury插件教程(上)

    [转] 设计师和开发人员更快完成工作需求的20个惊人的jqury插件教程(上) jquery的功能总是那么的强大,用他可以开发任何web和移动框架,在浏览器市场,他一直是占有重要的份额,今天,就给大家 ...