牛与电影

  题目大意:就是一群牛,又在玩游戏了(怎么你们经常玩游戏),这个游戏规则如下,把牛拆分成一个一个组,并且定义一个“度”,规定在一个组的牛与他自己的度为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)的更多相关文章

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

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

  2. POJ 2139 Six Degrees of Cowvin Bacon (floyd)

    Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Ja ...

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

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

  4. POJ:2139-Six Degrees of Cowvin Bacon

    传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...

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

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

  7. 任意两点间最短距离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 ...

  8. POJ 2139 Six Degrees of Cowvin Bacon

    水题,Floyd. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...

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

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

随机推荐

  1. 【kAri OJ604】圣哲的树

    时间限制 1000 ms 内存限制 65536 KB 题目描述 果园大咖圣哲有12个棵树,其中有且仅有一个是有病的,有病的树比真的或轻或重,给出3次天平测量重量的结果,每次告知左侧和右侧的树各有哪几个 ...

  2. POJ2186 Popular Cows

    Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...

  3. poj 3463 最短路与次短路&&统计个数

    题意:求最短路和比最短路长度多1的次短路的个数 本来想图(有)方(模)便(版)用spfa的,结果妹纸要我看看dijkstra怎么解.... 写了三遍orz Ver1.0:堆优化+邻接表,WA //不能 ...

  4. [NOIP2011] 提高组 洛谷P1315 观光公交

    题目描述 风景迷人的小城Y 市,拥有n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第 0 分钟出现在 1号景点,随后依次前往 2 ...

  5. Linux文件权限;ACL;Setuid、Setgid、Stick bit特殊权限;sudo提权

    相关学习资料 http://blog.sina.com.cn/s/blog_4e2e6d6a0100g47o.html http://blog.csdn.net/aegoose/article/det ...

  6. appium跑demo简单实例讲解

    安装appium,设置 demo.pyfrom appium import webdriver #要装webdriver,方法查看http://www.cnblogs.com/sincoolvip/p ...

  7. Activity启动模式 及 Intent Flags 与 栈 的关联分析

     http://blog.csdn.net/vipzjyno1/article/details/25463457    Android启动模式Flags栈Task   目录(?)[+] 什么是栈 栈 ...

  8. 如何通俗地理解 Gradle

    http://www.zhihu.com/question/30432152 一句话概括就是:依赖管理和任务执行. 像Ruby里面的bundler+rake,像iOS中的cocoapods,像node ...

  9. android 读取sd卡中的图片

    一.获取读取SD卡的权限 <!--在SDCard中创建与删除文件权限  -->    <uses-permission android:name="android.perm ...

  10. Circular Sequence,ACM/ICPC Seoul 2004,UVa 1584

    #include <stdio.h> #include <string.h> #define maxn 105 int lss(const char *s,int p,int ...