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头媒介牛, ...
随机推荐
- GPUImage学习
1.GLProgram--加载vertex和fragment的shader. 好处是完全将shader模块的加载过程独立出来. 学习:每个函数处理一件事,且函数的粒度刚好 在glLinkProgram ...
- list 和 str
list 和 str 两种类型数据,有不少相似的地方,也有很大的区别.本讲对她们做个简要比较,同时也是对前面有关两者的知识复习一下,所谓“温故而知新”. 相同点 都属于序列类型的数据 所谓序列类型的数 ...
- ARP协议格式、ARP运行机制入门学习
相关学习资料 http://baike.baidu.com/view/149421.htm?fromtitle=ARP%E5%8D%8F%E8%AE%AE&fromid=1742212& ...
- 网页设计师常用的PHOTOSHOP插件
Photoshop是网页设计师常用的一个非常重要而强大的工具,可以让网页设计师的工作高效便捷的进行,也为设计师们的天马行空提供了实际技术实现.一般我们的网页设计师设计完成后,需要将其转换制作成网页形式 ...
- if,switch,do,while,for实例
1.#include <stdio.h>void f1(int i){ if( i < 6 ) { printf("Failed!\n" ...
- Shell编程检测监控mysql的CPU占用率
shell编程很强大! 网站访问量大的时候mysql的压力就比较大,当mysql的CPU利用率超过300%的时候就不能提供服务了,近乎卡死状态,这时候最好的方法就是重启mysql服务.由于这种事具有不 ...
- RSA算法小记
学习来源:http://www.cnblogs.com/vamei/p/3480994.html 小记: 一.数学基础: 欧拉Phi函数:Φ(n)=总数(从1到n-1中与n互质的整数) (1)欧拉定理 ...
- [STL] lower_bound和upper_bound
STL中的每个算法都非常精妙, ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一 ...
- dll劫持技术
DLL劫持技术当一个可执行文件运行时,Windows加载器将可执行模块映射到进程的地址空间中,加载器分析可执行模块的输入表,并设法找出任何需要的DLL,并将它们映射到进程的地址空间中. DLL劫持原理 ...
- 关于FlexPaper 2.1.2版本 二次开发 Logo 、打印、搜索、缩略图、添加按钮、js交互、右键菜单、书签等相关问题
2015-03-02 更新文章,由于需求修改,更改了flexpaper插件,故增加第9.10.11小节,下载代码时请注意. 先废话几句.最近用到文档在线浏览功能,之前用的是print2flash(一个 ...