牛与电影

  题目大意:就是一群牛,又在玩游戏了(怎么你们经常玩游戏),这个游戏规则如下,把牛拆分成一个一个组,并且定义一个“度”,规定在一个组的牛与他自己的度为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. BIEE 后台新建分析没有你创建的数据源

    (1)登录http://win-5rnnibkasrt:9704/analytics/saw.dll?bieehome  点击“管理” 找到“发出SQL语句”在里面写call sapurgeallca ...

  2. BZOJ-3231 递归数列 矩阵连乘+快速幂

    题不是很难,但是啊,人很傻啊...机子也很鬼畜啊... 3231: [Sdoi2008]递归数列 Time Limit: 1 Sec Memory Limit: 256 MB Submit: 569 ...

  3. HDU-1754I Hate It 线段树区间最值

    这道题比较基本,就是用线段树维护区间最值,可以算是模板吧-.. I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768 ...

  4. 修改MYSQL 表中的字段属性

    1.登录数据库 >mysql -u root -p 数据库名称 2.查询所有数据表 >show tables; 3.查询表的字段信息 >desc 表名称; 4.1.修改某个表的字段类 ...

  5. eclipse中文乱码问题解决方案

    eclipse之所以会出现乱码问题是因为eclipse编辑器选择的编码规则是可变的.一般默认都是UTF-8或者GBK,当从外部导入的一个工程时,如果该工程的编码方式与eclipse中设置的编码方式不同 ...

  6. App接口中xml方式封装通信接口

  7. Fast-cgi cgi nginx php-fpm 的关系 (转

    Fast-cgi  cgi  nginx  PHP-fpm 的关系 Fast-cgi是由cgi发展而来,是http服务器(http,nginx等)和动态脚本语言(php,perl等)之间的的通信接口, ...

  8. javaweb学习总结(三十一)——国际化(i18n)

    一.国际化开发概述 软件的国际化:软件开发时,要使它能同时应对世界不同地区和国家的访问,并针对不同地区和国家的访问,提供相应的.符合来访者阅读习惯的页面或数据. 国际化(internationaliz ...

  9. centos 搭建gitlab

    #修改yum源 yum -y install wget cd /etc/yum.repos.d wget -O CentOS-Base.repo http://mirrors.aliyun.com/r ...

  10. Js注册等待

    <为维护网上公共秩序和社会稳定,请您自觉遵守以下条款: <br> <br>  一.不得利用本站危害国家安全.泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用 ...