Poj 2139 Six Degrees of Cowvin Bacon (floyd最短路)

FC7300 SPI MCAL配置引导 Example - QMI8A01z外设:Example - QMI8A01z外设: 阅读详情
 Six Degrees of Cowvin Bacon

===========================

             Time Limit: 1000MS
             Memory Limit: 65536K
            Total Submissions: 3993

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没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2。以此类推,a与b之间有n头媒介牛,那么a,b的度为n+1。 给出m部电影,每一部给出牛的个数,和牛的编号。问那一头到其他每头牛的度数平均值最小,输出最小平均值乘100。

题解:到所有牛的度数的平均值最小,也就是到所有牛的度数总和最小。那么就是找这头牛到其他每头牛的最小度,也就是最短路径,相加再除以(n-1)就是最小平均值。对于如何确定这头牛,我们可以枚举,最后记录最下平均值即可。

代码如下:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=350;
int map[N][N];
int n,m;
int s[N];
void init()    //初始化
{
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            if(i!=j)
                map[i][j]=1e9;   //初始化为较大的值
            else
                map[i][j]=0;
}
void Flyod()   //弗洛伊德函数
{
    int i,j,k;
    int  minsum,sum;
    long long ans=0;
    //floyd-warshall 算法核心语句  松弛
    for(k=1; k<=n; k++)
        for(i=1; i<=n; i++)
            for(j=1; j<=n; j++)
                map[i][j]=min(map[i][j],map[k][j]+map[i][k]);
    minsum=100000000;   //定义一个较大的最小值,然后不断更新他的最小值
    for(i=1; i<=n; i++)   //枚举每一头牛
    {

        sum=0;
        for(j=1; j<=n; j++)
            sum+=map[i][j];  //记录到其他牛的度的最小值和

        if(minsum>sum)   //不断更新最小值
            minsum=sum;
    }

    cout<<minsum*100/(n-1)<<endl;   //输出其平均值的100倍
}
int main()
{
    while(cin>>n>>m)
    {
        int mi;
        init();
        for(int i=1; i<=m; i++)
        {
            cin>>mi;
            for(int j=1; j<=mi; j++)
                cin>>s[j];
            for(int j=1; j<=mi; j++)  //将度入到map数组中
                for(int k=j+1; k<=mi; k++)
                {
                    map[s[j]][s[k]]=1;
                    map[s[k]][s[j]]=1;
                }

        }
        Flyod();
    }
    return 0;
}
CesiumJS【Basic】- #002 加载在线瓦片地图数据 cesiumjs 加载各类在线地图数据 阅读详情

相关推荐

什么是plm系统?-数字化转型网

当今世界,产品研发能力是企业在激烈的市场竞争中保持战略优势的核心竞争力之一。如何有效地缩短产品研发周期、改善产品服务的设计迭代流程、有效降低产品的研发成本,也是企业面临的主要问题之一。PLM(Product Lifecycle Management,产品生命周期管理)在优化产品研发的全管理流程、增强企业产品的市场竞争力方面具有关键的作用。

cxo17757154043的博客 889

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

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

NightWind 1145

京东商品数据爬取实战:用Selenium+代理IP绕过最新反爬机制(附完整代码)

本文深入解析京东商品数据采集技术,详细介绍了如何利用Selenium与智能反反爬策略绕过京东最新的反爬机制。通过实战案例和完整代码,帮助开发者掌握高效采集京东商品数据的方法,包括动态参数加密、行为验证识别及分布式采集架构设计等关键技术。

cc789的博客 1065

poj 2139 Six Degrees of Cowvin Bacon 图论 Floyd最短路

《挑战》练习题,图论最短路基础,Floyd算法。

ned_chu的博客 544

小红书图文AI创作:输入主题,一键生成图文(coze工作流教程+获取)

输入主题,工作流一键生成小红书风格图文,30s一条,可批量生成

2301_79384090的博客 2805

UR5 机械臂手眼标定(Eye-in-Hand)实战:OpenCV 求解 AX=XB,误差 < 2mm

本文详细介绍了UR5机械臂在Eye-in-Hand配置下的手眼标定实战,通过OpenCV实现高精度标定,最终达到误差小于2mm的工业级精度要求。文章涵盖了标定基础原理、环境搭建、数据采集策略、核心算法实现及误差分析与优化,为视觉机械臂的自主抓取提供了实用指南。

weixin_31476015的博客 302

Six Degrees of Cowvin Bacon (poj 2139 最短路Floyd)

题意:英语太差,读题就读了半小时快哭了 n头牛,m行关系,每一行先输入头数num,紧接着num头牛,这num头牛两两之间距离为1,最后问哪一头牛到其他所有牛距离的平均值最小,ans=到其他所有牛的最短距离之和*100/(n-1)。

@you! 1426

2024年全国大学生电子设计竞赛A题_AC-AC变换电路并联运行

AC-AC变换电路并联运行(A 题)【本科组】

qq_74395263的博客 7860

POJ 2139 Six Degrees of Cowvin Bacon Floyd最短路

POJ2139 Description The cows havebeen making movies lately, so they are ready to play a variant of the famousgame "Six Degrees of Kevin Bacon".  The game works like this: each cow is considered t

小萨摩的博客 322

告别复杂配置!用GuidosToolbox 3.0做MSPA景观格局分析,从安装到出图全记录

本文详细介绍了如何使用GuidosToolbox 3.0进行MSPA景观格局分析,从安装配置到出图全流程。涵盖环境准备、数据预处理、参数设置、结果解读及可视化技巧,帮助用户快速掌握这一生态安全评估工具。特别针对安装教程中的常见问题提供解决方案,提升分析效率。

weixin_29248313的博客 494

32、机械臂数字孪生模型创建指南

本文介绍了如何在MATLAB Simscape中为一款3自由度(DOF)微型机械臂创建数字孪生模型。内容涵盖硬件参数测量、Simulink模型搭建流程,包括初始条件设置、基座与上部主体构建、上臂结构设计等关键步骤。通过使用Solid、Revolute Joint和Rigid Transform等模块,实现机械臂多体系统建模,并支持后续运动仿真与物理系统的对比诊断。读者可依据指南逐步完成模型构建,相关资源可通过MATLAB File Exchange或指定网站获取。

qsc9012345的博客 218

【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)

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

Sky丨Star的博客 101

物联网通信中NB-IoT、Cat.1、LTE-M该如何选择?

首先我们要确定我们产品的关键需求,例如:我们的设备是否对数据传输速率有较高的要求,有较高要求我们就需要选择较高传输速率的Cat.1来开发我们的产品。同时关于产品性能方面,我们对功耗、延迟、可靠性也会有所要求,例如我们的产品为移动端产品,不方便布线以及安装电源,那我们就会采用电池供电的方式,所以在选择时可以优先考虑低功耗产品,最终结合其他需求选择出合适的协议。首先,我们需求的产品是不同的,我们需要根据产品需求或项目需求来进行选择,NB-IoT、Cat.1、Cat.M都有属于自己的优势。

a1809032425的博客 1220

POJ2139 Six Degrees of Cowvin Bacon【Floyd算法】

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 527

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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

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 zer

Halo 641

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ 2139 Six Degrees of Cowvin Bacon(任意两点最短路,Floyd)

题目:http://poj.org/problem?id=2139 题意:奶牛们最近要拍电影了(ACM真是各种奶牛。。。) 1、若两个的奶牛一起工作则,他们相互的度(degrees)为1; 2、若两只奶牛a、b不一起工作,但与另有一只奶牛都和他们工作,则a、b的相互的度为2。 求奶牛的与其他奶牛的度的平均值的一百倍的整数。 #include<iostream> ...

Tongqi 684

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

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

codeswarrior的博客 433

POJ 2139 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 "Six Degrees of Kevin Bacon". The game works like this: each cow is considered to be zero degrees of sep...

weixin_34127717的博客 101

A - Six Degrees of Cowvin Bacon POJ - 2139 最短路Floyd

实在是坑在输出这里wa了好几发 注意是输出是整数整数整数的形式我至今不明为何 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

galesaur_wcy 264

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 1512

POJ 2139 Six Degrees of Cowvin Bacon (Floyd)

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 525

POJ - 2139 Six Degrees of Cowvin Bacon floyd裸题

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

WA是一笔财富 496

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的博客 236

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 420

POJ-2139:Six Degrees of Cowvin Bacon【floyd小水题】

原题传送门 第一遍读题竟然理解错了,想了半天没个思路,为自己的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的博客 279

POJ 2139 Six Degrees of Cowvin Bacon (floyd)

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的博客 195
上一篇: Floyd(弗洛伊德)算法 详解+模板
下一篇: Kruskal(克鲁斯卡尔) 最小生成树 算法详解+模板
Puppet__
博客等级 码龄10年 319粉丝 328原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值