牛与电影

  题目大意:就是一群牛,又在玩游戏了(怎么你们经常玩游戏),这个游戏规则如下,把牛拆分成一个一个组,并且定义一个“度”,规定在一个组的牛与他自己的度为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. 解决already defined in .obj 的问题(定义/声明的区别)

    首先需要搞清楚什么是定义(definition ),什么是声明(declaration). 一.函数 函数的声明: int myfunc(int a,int b); 定义: int myfunc(in ...

  2. 【UVALive 7334】Kernel Knights

    题 题意 有两个队的骑士1到n和n+1到2n,每个骑士只能互相攻击对手队的一个骑士.kernel的意思是在这个kernel里的骑士不会互相攻击,在kernel外的骑士被kernel里的骑士攻击. 现在 ...

  3. BIEE 维表

    (1)       在物理层给表创建别名(表——>新建对象——>别名) (1)       在业务层创建维度(表——>创建逻辑维——>基于级别层次的维) 钻取是维本身的功能 一 ...

  4. vbox下安装arch

    http://tieba.baidu.com/p/2663744019 安装介质: archlinux-2013.10.01-dual.iso 准备存储设备: 警告: 磁盘分区有时会毁掉原分区内的数据 ...

  5. Dedecms include\dialog\select_soft_post.php Upload Any Files To The Specified Directory Via Variable Not Initial Flaw Bypass Extension Defence

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 综合来说,这个漏洞的根源是"register_globals = on& ...

  6. IOS基础之 (二) 面向对象思想

    编写Objective-C程序时,要使用Foundation框架. 什么是框架? 框架(framework)是由很多类(class)组成的库,可以用来编写程序. 对象(Object) 对象可以保存数据 ...

  7. 关于Asp.Net Mvc3.0 使用KindEditor4.0 上传图片与文件

    http://blog.csdn.net/fyxq14hao/article/details/7245502 今天我们的Asp.Net Mvc 3的项目中,把KindEditor3.9改为 KindE ...

  8. zabbix 汉化

    zabbix2.x的版本自带汉化,3.x的版本也可以通过修改配置文件强制使用自带的汉化,但是不管哪种,翻译的精准度令人费解:偶然发现一个专门翻译zabbix的网站https://www.zabbix. ...

  9. Starting zabbix_agentd: No such file or directory

    问题描述 [root@localhost admin]# service zabbix_agentd restart Shutting down zabbix_agentd: [FAILED] Sta ...

  10. C语言or和and运算

    #include <stdio.h> void main () { printf( | ); printf( | ); printf( | ); printf( | ); printf( ...