ShortestPath:Six Degrees of Cowvin Bacon(POJ 2139)

题目大意:就是一群牛,又在玩游戏了(怎么你们经常玩游戏),这个游戏规则如下,把牛拆分成一个一个组,并且定义一个“度”,规定在一个组的牛与他自己的度为0,与其他牛的度为1,不同组的牛不存在度,但是如果牛与牛之间有联系,那么度就会想加,这一题所有的牛都会与其他所有的牛有联系,问你哪只牛与其他牛的度的总数最少,求这个总数的平均值。
那么这一题貌似把牛拆分成一个一个的区间,但是我们仔细想一下,其实啊这个组是不重要的,他只是影响了牛与牛之间有没有直接相连,其实仔细读下来我们直接建图就可以了,每一次一个组的信息我们都把组内的牛建立联系就行了
现在要求所有牛的最短距离,那么就是用Floyd算法了,很简单的代码
#include <iostream>
#include <functional>
#include <algorithm>
#define MAX_N 301 using namespace std; static int Gragh[MAX_N][MAX_N];
static int Dist[MAX_N][MAX_N];
static int tmp[MAX_N]; void Create_Gragh(const int);
void Search(const int); int main(void)
{
int Movie_sum, cow_sum, in_movie_sum;
while (~scanf("%d%d", &cow_sum, &Movie_sum))
{
memset(Gragh, , sizeof(Gragh));
for (int i = ; i < Movie_sum; i++)
{
scanf("%d", &in_movie_sum);
for (int j = ; j < in_movie_sum; j++)
scanf("%d", &tmp[j]);
Create_Gragh(in_movie_sum);
}
Search(cow_sum);
}
return ; } void Create_Gragh(const int in_movie_sum)
{
for (int i = ; i < in_movie_sum; i++)
{
for (int j = i + ; j < in_movie_sum; j++)
{
Gragh[tmp[i]][tmp[j]] = ;
Gragh[tmp[j]][tmp[i]] = ;
}
}
} void Search(const int cow_sum)//Floyd算法,dp数组
{
int min_sum = INT_MAX, sum;
for (int i = ; i <= cow_sum; i++)//初始化
{
for (int j = ; j <= cow_sum; j++)
{
if (i == j) Dist[i][j] = ;
else if (Gragh[i][j] == ) Dist[i][j] = ;
else Dist[i][j] = MAX_N + ;
}
}
for (int k = ; k <= cow_sum; k++)//最短寻路
{
for (int i = ; i <= cow_sum; i++)
for (int j = ; j <= cow_sum; j++)
{
if (i == j) continue;
Dist[i][j] = min(Dist[i][j], Dist[i][k] + Dist[k][j]);
}
}
for (int i = ; i <= cow_sum; i++)//和其他点都有关系,我们找到那个最小平均值即可
{
sum = ;
for (int j = ; j <= cow_sum; j++)
sum += Dist[i][j];
min_sum = sum < min_sum ? sum : min_sum;
}
printf("%d\n", min_sum * / (cow_sum - ));
}

ShortestPath:Six Degrees of Cowvin Bacon(POJ 2139)的更多相关文章
- 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 (floyd)
Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Ja ...
- 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)
Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
- 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 最短路径问题 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 ...
- 任意两点间最短距离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 ...
- POJ 2139 Six Degrees of Cowvin Bacon
水题,Floyd. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...
- POJ 2139 Six Degrees of Cowvin Bacon (Floyd)
题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...
随机推荐
- Java编程思想学习(三) 初始化与清理
1. 每个重载的方法都必须有独一无二的参数类型列表.(参数顺序的不同也足以区分两个方法,但不建议这样做,会使代码难以维护.) 2. 方法重载时,如果可以重载的方法间只是参数类型不同,传入的数据类型(实 ...
- SQL多条件查询
SELECT a.tel,a.business_code,b.name AS business_name,a.register_time FROM T_RED_USER a LEFT JOIN T_P ...
- ubuntu安装spark on yarn
安装spark 安装hadoop 安装ssh,调试免密钥登录 配置hadoop 配置yarn 测试
- 如何在 Arch Linux 的终端里设定 WiFi 网络
如果你使用的是其他 Linux 发行版 而不是 Arch CLI,那么可能会不习惯在终端里设置 WiFi.尽管整个过程有点简单,不过我还是要讲一下.在这篇文章里,我将带领新手们通过一步步的设置向导,把 ...
- centos6.3配置MFS服务器
一.简介 MooseFS(Moose File System,mfs)是一种分布式文件系统,它将数据分布在网络中的不同服务器上,支持FUSE(用户空间文件系统Filesystem in Userspa ...
- Redis 下载
https://github.com/MSOpenTech/redis/releases下载 Redis伴侣Redis Desktop Manager:http://redisdesktop.com/ ...
- ios严格检验身份证号码有效性
+ (BOOL)checkIDCard:(NSString *)sPaperId { //判断位数 && sPaperId.length != ) { return NO; } NSS ...
- sqlmap注入检测
1.列出可利用数据库: sqlmap -u url --dbs 2.列出某个数据库中表: sqlmap -u url --tables -D south sqlmap -u ur ...
- php导出excel
感觉技术掌握的有些太杂了,一会儿鼓捣java,一会儿鼓捣php,一边还搞着.net, maybe this just is life. 此前同事给某县政法委做的一套维稳信息平台,数据库是封装了mysq ...
- 文件系统:drbd主备服务器文件同步
一. DRBD介绍 DRBD是一种块设备,可以被用于高可用(HA)之中.它类似于一个网络RAID-1功能.当你将数据写入本地 文件系统时,数据还将会被发送到网络中另一台主机上.以相同的形式记录在一个文 ...