Six Degrees of Cowvin Bacon POJ - 2139 (floyd求最短路)

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

Six Degrees of Cowvin Bacon

POJ - 2139

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(连通),如果两头牛没有在一个电影中过,但是有一头牛和这两头牛分别在同一个电影中过,则这两头牛之间也算作1,
这样一想就是一个图,给定a b说明ab直接相连给定ab bc  则ac也间接相连,求一个牛到其他所有的牛的距离最小(每个距离为1),就是求最短路,可以用弗洛伊德算法,然后枚举每个点,最终得到结果
code:
#include <iostream>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
int G[303][303];
int n,m;
int x[303];
int main(){
    memset(G,INF,sizeof(G));
    cin >> n >> m;
    int i,j,k;
    for(i = 0; i < n; i++)
        G[i][i] = 0;//必须有这句
    while(m--){
        int num;
        cin >> num;
        for(i = 0; i < num; i++){
            cin >> x[i];
            --x[i];
        }
        for(i = 0; i < num; i++){
            for(j = i+1; j < num; j++){
                G[x[i]][x[j]] = 1;
                G[x[j]][x[i]] = 1;
            }
        }
    }
    //folyd
    for(k = 0; k < n; k++){
        for(i = 0; i < n; i++){
            for(j = 0; j < n; j++){
                G[i][j] = min(G[i][j],G[i][k]+G[k][j]);
            }
        }
    }
    int sum,ans = INF;
    for(i = 0; i < n; i++){
        sum = 0;
        for(j = 0; j < n; j++){
            sum += G[i][j];
        }
        ans = min(ans,sum);
    }
    cout << 100*ans/(n-1) << endl;//n-1 except himself
    return 0;
}




Six Degrees of Cowvin Bacon短路 原题链接 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4687 Accepted: 2233 DescriptionThe cows have been making movies lately, so they are ready to pla 阅读详情

相关推荐

POJ 2139——Six Degrees of Cowvin Bacon 短路

原题如下: 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 consider

say_c_box的博客 514

【PAT数据结构与算法题目集】六度空间(多源短路径)

【PAT数据结构与算法题目集】六度空间(多源短路径) 题目 六度空间理论称作六度分隔Six Degrees of Separation)”理论。这个理论可以通俗阐述为:“你任何一个陌生人之间间隔不会超过六个,也就是说,最多通过五个你就能够认识任何一个陌生人。” “六度空间理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试验证这个理论始终是许多社会学家努力...

hh66__66hh的博客 1819

数据结构---

木木的笔记 2307

POJ_2139_Six Degrees of Cowvin BaconFloyd

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description The cows have been making movies lately, so they are ready to play a variant of the famous g

持之以恒_fighting 362

POJ - 2139Six Degrees of Cowvin BaconFloyd算法短路

Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现缘也是可以被量化的,我们用一个到其他所有的平均距离来量化计算。 在这里定义的距离:1.自己与自己的距离为02.如果AB属于同一个小团体,那么他们之间的距离为13.如果A与B属于一个小团体,B与C属于一个小团体,且A与C不同属于任何一个小团体,那么A与C的距离为2(A联系C...

Sky丨Star的博客 97

POJ2139 Six Degrees of Cowvin BaconFloyd算法】

Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9822 Accepted: 4666 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

海岛Blog 514

POJ 2139 Six Degrees of Cowvin Bacon

Six Degrees of Cowvin Bacon Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2986   Accepted: 1390 Description The cows have been making movies lately, so they

Kimi_R_17 1505

POJ 2139 Six Degrees of Cowvin BaconFloyd

Six Degrees of Cowvin Bacon Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3289   Accepted: 1530 Description The cows have been making movies lately, so t

TaoSama's Microcosm 523

POJ - 2139 Six Degrees of Cowvin Bacon floyd裸题

传送门:POJ2139 题意:牛们近在拍电影,所以他们准备去玩一个游戏——“六度分割”的变体。 游戏是这样进行的:每个牛离自己的距离是0度,如果两个不同的牛同时出现在一个电影里,那么他们之间的距离为1度,如果两只牛从未一起工作,但它们都与第三只牛一起工作,那么他们之间的距离为2度。 这N(2 思路:任意两点间短距离,典型floyd,注意一下输出的时候取下整数就行了。 #include

WA是一笔财富 490

POJ - 2139 Six Degrees of Cowvin Bacon(任意两点短路Floyd

题目传送门 题意:奶牛们近要拍电影了…… 1、若两个的奶牛一起工作则,他们相互的度(degrees)为; 2、若两只奶牛a、b不一起工作,但与另有一只奶牛都他们工作,则a、b的相互的度为2。 奶牛的与其他奶牛的度的平均值的一百倍的整数。 转换成则是一个点到其他点距离的平均值的一百倍。 (任意两点短路Floyd) #define _CRT_SECURE

NightWind 1142

Six Degrees of Cowvin Bacon POJ - 2139

题目: 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 ...

titi2018815的博客 232

POJ2139 Six Degrees of Cowvin Bacon

题目来源:http://poj.org/problem?id=2139 题意:有N只牛,在同一部电影Mi里的Ni只牛它们之间的距离为1,当两只牛不在同一部电影里,有第三只牛分别在那两只牛拍的电影里,则它们的距离为2。要的是以其中一只牛为起点与其他牛之间的距离之短。 N #include #include #include using namespace std; const int

sun_apple_123 415

POJ-2139:Six Degrees of Cowvin Baconfloyd小水题】

原题传送门 第一遍读题竟然理解错了,想了半天没个思路,为自己的zz买单 orz 题意 开始的时候所有奶牛的度为0(自己到自己的距离为0),在一个movie工作过的奶牛度为1,即给定一个movie,所有奶牛两两距离为1,有一句话比较绕口 If a two cows have never worked together but have both worked with a third cow, t...

csyifanZhang的博客 278

POJ 2139 Six Degrees of Cowvin Baconfloyd

Six Degrees of Cowvin Bacon Time Limit:1000MS Memory Limit:65536K Total Submissions:6744 Accepted:3139 Description The cows have been making movies lately, so ...

Lily1221的博客 193

POJ 2139 Six Degrees of Cowvin Bacon短路

Six Degrees of Cowvin Bacon 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

nudt_oys的博客 432

POJ 2139 Six Degrees of Cowvin Bacon 短路

题目链接 Sample Input 4 2 3 1 2 3 2 3 4 Sample Output 100 题目大意: 给定 n, m. 之后m行,每行是一个集合。 每一个集合里任意两个元素之间的距离都是1. 一个点,这个点到其余所有点的距离小,即 ans令 ∑dis[ans][i] (1=<i<=n 且i不等于ans) 然后输出平均距离(乘100倍保留整数)...

RPG_Zero的博客 182

POJ 2139 Six Degrees of Cowvin Baconfloyd)

就是用floyd一个点点短距离然后个平均值 题目: Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2359 Accepted: 1116 Description The cow...

aiezhen1717的博客 134

POJ-2139-Six Degrees of Cowvin Bacon

Six Degrees of Cowvin Bacon Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7024   Accepted: 3259 Description The cows have been making movies lately, so they are ready ...

YIU 227
上一篇: 折线分割平面 HDU - 2050 (找规律)
下一篇: Agri-Net POJ - 1258 (最小生成树)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值