POJ2139-Six Degrees of Cowvin Bacon-(Floyd_Warshall)
题意:有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)的更多相关文章
- POJ 2139 Six Degrees of Cowvin Bacon (Floyd)
题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...
- 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)
Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
- POJ2139 Six Degrees of Cowvin Bacon [Floyd]
水题,随手敲过 一看就是最短路问题,a,b演同一场电影则他们的距离为1 默认全部两两原始距离无穷,到自身为0 输入全部数据处理后floyd 然后照它说的求平均分离度 再找最小的,×100取整输出 #i ...
- 【Floyd】POJ2139 -Six Degrees of Cowvin Bacon
普通的Floyd了分分秒可以水过,结果在submit前删调试段落的时候把程序本体给删了吃了两个WA…… #include<iostream> #include<cstring> ...
- poj2139 Six Degrees of Cowvin Bacon
思路: floyd 实现: #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- 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
传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...
- 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 最短路径问题 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 ...
随机推荐
- mysql启动报错 "unknown variable 'defaults-file=/etc/my.cnf"
使用指定的my.cnf,而不用默认的/etc/my.cnf文件,可以在启动时,在mysqld_safe后加上参数--default-file=/usr/local/server/mysql2/etc/ ...
- 使用预编译库PREBUILT LIBRARY官方说明
使用预编译库 NDK 支持使用预编译库(同时支持静态库和共享库).此功能有以下两个主要用例: 向第三方 NDK 开发者分发您自己的库(而不分发您的源代码). 使用您自己的库的预编译版本来提升编译速度. ...
- 【题解】分离与合体 [Loj10151]
[题解]分离与合体 [Loj10151] 传送门:分离与合体 \([Loj10151]\) [题目描述] 给定一个长度为 \(n\) 的序列,如果从某个点 \(k\) 处将区间 \([l,r]\) 断 ...
- 部署elasticsearch(三节点)集群+filebeat+kibana
用途 ▷ 通过各个beat实时收集日志.传输至elasticsearch集群 ▷ 通过kibana展示日志 实验架构 名称:IP地址:CPU:内存 kibana&cerebro:192.168 ...
- latex制作表格-跨行跨列
1.列的合并,使用 \multicolumn{跨几列}{格式}{填充内容} \documentclass[UTF8]{ctexart} \begin{document} 三囚犯问题进行300次实验后\ ...
- Kafka Streams的Data Types and Serialization
Avro <repositories> <repository> <id>confluent</id> <url>http://packag ...
- os.mkdir()与 shutil.rmtree()对文件夹的 创建与删除
import osimport shutil # os.mkdir('C:/Users/Desktop/123') # 表示在桌面上创建文件# os.mkdir('123') # 表示在此代码文件下创 ...
- CodeForces 536D Tavas in Kansas
洛谷题目页面传送门 & CodeForces题目页面传送门 A和B在一张无向连通图\(G=(V,E),|V|=n,|E|=m\)上玩一个游戏,节点\(i\)有一个权值\(v_i\).A.B分别 ...
- Serverless
一.介绍 是指依赖于第三方应用程序或服务来管理服务器端逻辑的应用程序. 此类应用程序是基于云的数据库(如Google Firebase)或身份验证服务. 无服务器也意味着开发为事件触发的代码,并且在无 ...
- Computer Neworking: A Top-Down Approach
目录 Chapter 1: Computer Networks and the Internet 1. What is the Internet? 2. The Network Edge 3. The ...