题意:有n只牛拍电影m部电影,知道每部电影有哪些牛参与,一起拍电影的牛之间维度为1,ab拍电影则ab之间的维度为1,如果bc一起拍电影,ac没有一起,则ac之间的维度为2,以此类推。求哪知牛到所有牛之间的总维度和最小。

解题:任意两点之间的距离,佛洛依德无脑三重暴力求最短路。

//记录一下模板

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; int n,m,k;
int a[][];
int b[]; void Floyd_Warshall()//弗洛伊德算法
{
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
a[i][j] = min( a[i][j],a[i][k]+a[k][j] );///k作为i和j之间的连接点
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(a,inf,sizeof(a));
for(int i=;i<;i++)
a[i][i]=; while(m--)
{
scanf("%d",&k);///这部电影里有k头牛
for(int i=;i<k;i++)
scanf("%d",&b[i]);
for(int i=;i<k;i++)
for(int j=i+;j<k;j++)
a[ b[i] ][ b[j] ] = a[ b[j] ][ b[i] ] = ;///一部电影里的任意两头牛之间的度为1
}
Floyd_Warshall();
int ans=inf;
for(int i=;i<=n;i++)///遍历每个点
{
int sum=;
for(int j=;j<=n;j++)///求i点到其他所有点的距离之和
sum+=a[i][j];
ans=min( ans,sum );
}
printf("%d\n",ans*/(n-)); }
return ;
}

POJ2139-Six Degrees of Cowvin Bacon-(Floyd_Warshall)的更多相关文章

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

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

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

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

  3. POJ2139 Six Degrees of Cowvin Bacon [Floyd]

    水题,随手敲过 一看就是最短路问题,a,b演同一场电影则他们的距离为1 默认全部两两原始距离无穷,到自身为0 输入全部数据处理后floyd 然后照它说的求平均分离度 再找最小的,×100取整输出 #i ...

  4. 【Floyd】POJ2139 -Six Degrees of Cowvin Bacon

    普通的Floyd了分分秒可以水过,结果在submit前删调试段落的时候把程序本体给删了吃了两个WA…… #include<iostream> #include<cstring> ...

  5. poj2139 Six Degrees of Cowvin Bacon

    思路: floyd 实现: #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  6. AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...

  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 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Ja ...

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

  10. 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. 微信公众号 --- 获取access_token

    获取access_token 在左侧菜单栏中也可以找到 可以一步步的进行设置  ,  身份验证的时候要 注意:密码是你创建微信公众号的密码 往一步步的执行就可以了 接下来就是获取ip 白名单,进行设置 ...

  2. C++完全二叉树的权值

    #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> int ...

  3. Replication:事务复制 Transaction and Command

    事务复制使用 dbo.msrepl_transactions 和 dbo.MSrepl_commands 存储用于数据同步的Transaction和Command.在replication中,每个co ...

  4. 服务器同时安装python2支持的py-faster-rcnn以及python3支持的keras

    最近把服务器折腾一下,搞定这两个.

  5. Oracle的约束

    学习笔记: ##约束     *概念:限定用户输入的内容.     *案例:         *练习             * 1. 在score表的grade列添加CHECK约束,限制grade列 ...

  6. C#桌面程序启动时传入参数

    using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms; namespac ...

  7. Centos7安装Tomcat7,并上传JavaWeb项目

    一.需要的工具(其他连接工具也行) 1.Xshell 2.XFTP 1.1首先将Tomcat7的压缩文件利用XFTP上传到Centos7系统上的 /etc/local/tomcat中 1.2 解压文件 ...

  8. 手写Ajax的意义所在,从青铜到钻石!

    话说菩提祖师打了孙猴子三板子  然后悟空学会72般变化以及一身神通 对待这个问题作为面试者要思考更加深层次的意义 才更能获得认可 实际上写的ajax 很能看出一个的水平 贴几段代码就可以看出水平的高低 ...

  9. Spring中获取外部配置文件中的属性值

    很多时候需要将配置信息从程序中剥离粗来,Spring现在提供的方法是通过@Value注解和<context:placeholder>来获取配置文件中的配置信息.这里给出一个简单的例子. 首 ...

  10. Solr新特性【4.x,5.x,6.x,7.x】

    一.Solr4.x新特性 1.近实时搜索 Solr的近实时搜索[Near Real-Time,NRT]功能实现了文档添加到搜索的快速进行,以应对搜索快速变化的数据. 2.原子更新与乐观并发 原子更新功 ...